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

Why is my math.random statement being ignored?

Asked by 5 years ago

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.

01local generatedName = math.random(1,2)
02local name = script.Parent.Stats.LastName.Value
03wait(1)
04if generatedName == 1 then
05name = "Smith"
06end
07if generatedName == 2 then
08name = "Jones"
09end
10print('Done.')

Any idea will be helpful, thank you.

1 answer

Log in to vote
1
Answered by
Azarth 3141 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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.

1local generatedName = math.random(1,2)
2local name = script.Parent.Stats.LastName
3wait(1)
4if generatedName == 1 then
5    name.Value = "Smith"
6else
7    name.Value = "Jones"
8end
9print('Done.', name.Value)
0
Thank you so much! Aeroporia 37 — 5y
Ad

Answer this question