Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

The number hits 100, but the part doesn't want to move?

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)

4 comments

0

try to do >=

0

Use "math.random(1, 100)".

0

this script isn't random, it hits 100 after 100 iterations every time. you need to check if math.random(100) is equal to 100, not number.

0

@youtubemasterWOW math.random(1, 100) and math.random(100) does the same thing.

2 answers

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.