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

math.random not working at all?

Asked by 6 years ago

I don't know what's wrong with this script.

local Part = game.Workspace.Part
Part.Transparency = 1
while true do
    wait(.5)
    parsttochosefrom = math.random(1,2)
    if parsttochosefrom == 1 then
        Part.Transparency = 1
        end
    if parsttochosefrom == 2 then
        Part.Transpacency = .5
    end

3 answers

Log in to vote
0
Answered by 6 years ago

on line 10, you spelled "transparency" wrong. Also, try using an elseif statement like this:

local Part = game.Workspace.Part
Part.Transparency = 1
while true do

    wait(.5)

    parsttochosefrom = math.random(1,2)

    if parsttochosefrom == 1 then
        Part.Transparency = 1
    elseif parsttochosefrom == 2 then
        Part.Transparency = .5
    end

end
0
thanks ootheboss 32 — 6y
Ad
Log in to vote
0
Answered by
zyrun 168
6 years ago
Edited 6 years ago

There are a few solutions that could help you. These are them:

  • On line 12 put another "end" to end the while loop.

  • Throw a math.randomseed(tick()) in there.

  • Do elseif rather than another if

Try this code and see if it works:

local Part = game.Workspace.Part
Part.Transparency = 1

math.randomseed(tick()) -- Makes things more random
while true do
    wait(.5)
    parsttochosefrom = math.random(1,2)
    if parsttochosefrom == 1 then
        Part.Transparency = 1
    elseif parsttochosefrom == 2 then -- An elseif here will make the code more smooth and faster
        Part.Transparency = .5
    end
end -- You forgot this end here


0
it only seems to work once ootheboss 32 — 6y
0
Make line 7 like this: local parsttochosefrom = math.random(1,2). That shouldn't be the problem, but it should work properly either way...I'm sure of the problem zyrun 168 — 6y
Log in to vote
0
Answered by 6 years ago
    local Part = game.Workspace.Part
    Part.Transparency = 1
    while true do
        wait(.5)
        parsttochosefrom = math.random(1,2)
        if parsttochosefrom == 1 then
            Part.Transparency = 1
            end
        if parsttochosefrom == 2 then
            Part.Transpacency = .5
        end


PLEASE MARK THIS HELPFUL, DON'T JUST TAKE SCRIPT AND GO

0
I already got an answer but thanks for trying! ootheboss 32 — 6y

Answer this question