Hi ScriptingHelpers!
Messing around with some ROBLOX programming and I've ran into a really strange interaction I can't figure out.
This is my code:
for i, v in pairs (game.Workspace.PlayBase.Plates:GetChildren()) do local snum = string.sub(v.Name, 6) local rnum = math.random(8500, 9500) * snum local cl = Color3.fromRGB(rnum, rnum, rnum) local cl2 = Color3.fromRGB(math.random(8500, 9500) * snum, math.random(8500, 9500) * snum, math.random(8500, 9500) * snum) v.Color = cl2 -- OR cl. end
PlayBase.Plates:GetChildren() are 25 plates which are set up in a 5x5 grid.This code is trying to set a random pattern of colours. The code works, but there's a catch.
When I choose to set v.Color to "cl2" the brick colour generates in the way that I would expect, as seen from this gyazo.
However when I set the v.Color to just "cl", which in my head is generated in EXACTLY the same way as cl2, you can see it does not act in the same way.
In my head cl and cl2 are generated in the same way, with a new Color3.fromRGB value, with the R, G, and B values being generated by "math.random(8500, 9500) * snum". Why are the outcomes consistently different? Am I missing something?
You're only picking a random number once with c1. If you print out c1 there times you'll see they're all the same number.
Three of the same number make a grey color with rgb.
Instead create three variables or directly put the math.randoms in the parameters like you did with c12