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

Why is my math.random statement being ignored?

Alright so, I am making a simulation of life. I have a math.random of 1,100. Instead of picking the value when it should be, it just skips the if statement and goes straight to the next line of code. It just skips the math.random and just goes straight to the print line.

local generatedName = math.random(1,2)
local name = script.Parent.Stats.LastName.Value
wait(1)
if generatedName == 1 then
name = "Smith"
end
if generatedName == 2 then
name = "Jones"
end
print('Done.')

Any idea will be helpful, thank you.

1 answer

✓ Accepted answer

You are setting your name variable to the Value, which will be read only after you do that. Instead, you need to set name to LastName, then set the Value of LastName in your if statement.

local generatedName = math.random(1,2)
local name = script.Parent.Stats.LastName
wait(1)
if generatedName == 1 then
	name.Value = "Smith"
else
	name.Value = "Jones"
end
print('Done.', name.Value)

1 comment

0

Thank you so much!

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