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 4 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.

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

Log in to vote
1
Answered by
Azarth 3141 Moderation Voter Community Moderator
4 years ago
Edited 4 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.

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)
0
Thank you so much! Aeroporia 37 — 4y
Ad

Answer this question