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

math.random not working at all?

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

✓ Accepted answer

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

1 comment

0

thanks

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


2 comments

0

it only seems to work once

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

	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

1 comment

0

I already got an answer but thanks for trying!

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