I'm trying to make a random number script, that when it hits 100, it moves a part upward. It's hit 100 multiple times but it never moves the part.
part = script.Parent for number = 1, 180 do math.randomseed(tick()) print(math.random(100)) wait(1) if number == 100 then part.CFrame = part.CFrame * CFrame.new(0,0,10) script.Disabled = true end end
what am I doing wrong? (I'm not a great scripter so I could use some advice)
The problem is (as others have stated in the comments) that you're only checking the iterator 'number', which isn't assigned a random value. So it only fires once.
There's a simple fix for this:
part = script.Parent for number = 1, 180 do math.randomseed(tick()) local number2 = math.random(100) -- Number2 value is assigned print(number2) -- This prints the value of Number2 wait(1) if number2 == 100 then -- Now it is checking for a random value instead of the iterator part.CFrame = part.CFrame * CFrame.new(0,0,10) script.Disabled = true end end
Have a great day!
Try this script I don't know where your part is at first so it will just move to the position when it hits 100.
part = script.Parent for number = 1, 180 do math.randomseed(tick()) print(math.random(100)) wait(2) -- added 1 extra second if number == 100 then script.Parent.Position = script.Parent.Position + Vector3.new(0,0,10) -- Changed this script.Disabled = true end end
Make sure to look in output for the numbers being counted