i'm trying to make it get a random string but sometimes they both pick the same string how can I prevent that?
local Power= {"Earth", "Fire", "Lightning", "Water"} Player.Power.Element1.Value = Power[math.random(1, #Power)] Player.Power.Element2.Value = Power[math.random(1, #Power)]
Every math.random without a seed uses the same seed, and this creates the same result. To fix this, you can use Random.new().
local rand = Random.new(tick()) -- tick makes the seed different with every game launch local Power= {"Earth", "Fire", "Lightning", "Water"} Player.Power.Element1.Value = Power[rand:NextInteger(1, #Power)] Player.Power.Element2.Value = Power[rand:NextInteger(1, #Power)]
EDIT:
local rand = Random.new(tick()) -- tick makes the seed different with every game launch local Power= {"Earth", "Fire", "Lightning", "Water"} Player.Power.Element1.Value = Power[rand:NextInteger(1, #Power)] repeat -- Prevent the second value from being the same Player.Power.Element2.Value = Power[rand:NextInteger(1, #Power)] until Player.Power.Element2.Value ~= Player.Power.Element1.Value
If there are any errors, please comment.