kh_834
(sisyphus)
October 17, 2022, 12:53am
#1
My script only chooses ONE color when I try to make the color of an NPC’s torso a randomized color from a table. What’s what’s wrong with my script?
local bodycolor = script.Parent
local colorstbl = {"Dusty Rose", "Neon orange", "Bright yellow"}
local color = colorstbl[math.random(0,#colorstbl)]
bodycolor.TorsoColor = BrickColor.new(color)
ImJustSimo
(ImJustSimo)
October 17, 2022, 12:56am
#2
Try this:
local colorstbl = {"Dusty Rose", "Neon orange", "Bright yellow"}
local color = colorstbl[math.random(1,#colorstbl)]
print(color)
3 Likes
ImJustSimo
(ImJustSimo)
October 17, 2022, 12:59am
#3
I think the output was nil since you started with a 0
kh_834
(sisyphus)
October 17, 2022, 1:02am
#4
prints correctly, but when the body color is changed, it continues to change to orange.
kh_834
(sisyphus)
October 17, 2022, 1:04am
#5
okay i guess it works now? it just favors the color orange for some reason
You could try using Random.new() to achieve “more” randomness
Regarding the “randomness”:
math.random() has been update to use the same random algorithm as Random.new()
The decision mainly comes down to “fairness” as math.random() is a global random object. Essentially the state of the random object changes as you get the next pseudo random in the sequence so using the global random though convenient is not goint be be fair because other scripts may or may not call the next pseudo random in the sequence.
Random.new() create a new random object so you can guarantee the “fairness” a…
1 Like