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

math.random not working correctly?

So 1,125 is angel 126 is demon 127,250 is fallen angel.

I've gotten values from math.random that are higher then 125 but it still changes it to angel? what might the issue be and how would I fix it?

local ctc= math.random(1,250)

local try = ReplicatedStorage.PlayerStats[id].Tries.Value
if try > 0 then
	if ctc >= 1 or ctc <= 125 then
		print(ctc)
		event:FireServer()
		

		script.Value.Value ="Angel"
		
		--script.Parent.Continue.Visible = true
	elseif
		
		ctc == 126 then
		print(ctc)
		event:FireServer()
		
		script.Value.Value = "Demon"
		print(ctc)
	--script.Parent.Continue.Visible = true
	elseif
		ctc >= 127 or ctc <= 250 then
		print(ctc)
		event:FireServer()
		
		script.Value.Value = "Fallen-Angel"
		print(ctc)
		--script.Parent.Continue.Visible = true

	end
	elseif try <= 0 then
	script.Parent.Parent.Tries.Value = 0
	script.Parent.TextButton.Text = "No tries left!"

end

end

2 comments

0

People said and not or that's probably why it doesn't work.

0

I don't know for sure if this will work but put a space between ctc and = "local ctc = math.random(1,250)"

2 answers

Well, you've got that small or statement there for:

if ctc >= 1 or ctc <= 125 then -- You see that or?
-- ANGEL CODE

It's checking to see if ctc is greater than or equal to one OR if it's less than or equal to 125. ctc will ALWAYS be greater than 1. So, you should either remove that:

ctc >= 1 or

or you can just replace that or with an and so:

if ctc >= 1 and ctc <= 125 then -- Notice that new and
-- ANGEL CODE

Hope I helped! :)

Do what astrealdev said, but also at the top of your script you need to put


math.randomseed(os.time())

This makes it so calling math.random() returns true random numbers.

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