im trying to clone a part that gives points and put in a random X axis but it spawns in the same position

Viewed 18
local randomnumber = math.random(18,45)

while true do
    wait(1)
    local Pointgiver = game.ReplicatedStorage.Points:Clone()
    Pointgiver.Parent = game.Workspace
    Pointgiver.Position = Vector3.new(randomnumber,0.5,-0.6)
    Pointgiver.Transparency = 0
end

doesnt give any errors but it spawns in the same position, help me

1 Answers

That's because you generate the random number outside of the loop.

random number


Fix: Move local randomnumber = math.random(18,45) into the loop:

while true do
    wait(1)
    local Pointgiver = game.ReplicatedStorage.Points:Clone()
    Pointgiver.Parent = game.Workspace
    local randomnumber = math.random(18,45)
    Pointgiver.Position = Vector3.new(randomnumber,0.5,-0.6)
    Pointgiver.Transparency = 0
end

I suggest you to revise the core programming concepts of control flow / order of execution.

Related