Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 4 years ago

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)

0
try to do >= VVoretex 146 — 4y
0
Use "math.random(1, 100)". youtubemasterWOW 2741 — 4y
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. doggybite1 100 — 4y
0
@youtubemasterWOW math.random(1, 100) and math.random(100) does the same thing. Rinpix 639 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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!

Ad
Log in to vote
0
Answered by 4 years ago

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

Answer this question