|
| 25 Dec 2012 03:00 AM |
I need help with a test script. I am learning how to script for Roblox and I am starting off with a block that changes color when touched if b ==3 but everytime I join it sticks with only 1 number like 5 or 1 but never changes. Can you help?
local a = math.random(0,256) local b = math.random(1,5)
function onTouched(h) print(b) if b == 3 then script.Parent.Color = Color3.new(a, a, a) else print(FAILURE) end end script.Parent.Touched:connect(onTouched) |
|
|
| Report Abuse |
|
|
|
| 25 Dec 2012 03:07 AM |
Hiya.
Okay so Im not sure if what im going to suggest is correct for what you want, But im guessing it changes once and then it just stops working, or something Similar.
Right now you have your values outside the function, So they are choosing a number once and going to keep that number everytime. You might join the game and it choose 256 and 1, And it will stay like that. To fix this just put the Variables in the function so that everytime its ran they are different! :D
function onTouched(h) local a = math.random(0,256) local b = math.random(1,5) print(b) if b == 3 then script.Parent.Color = Color3.new(a, a, a) else print(FAILURE) end end script.Parent.Touched:connect(onTouched)
Again, if this wasn't what you were asking for, Sorry! :x |
|
|
| Report Abuse |
|
|
|
| 25 Dec 2012 03:13 AM |
| Exactly what I was asking! Thanks for the help! |
|
|
| Report Abuse |
|
|
| |
|
|
| 25 Dec 2012 05:08 AM |
| Lol, I can't script one bit. |
|
|
| Report Abuse |
|
|