So, Im trying to make a script for someone where if you touch it it randomly changes to either red, or green, but whenever I touch it, and don't touch it again it keeps changing. (no errors in the output because its doing what its supposed to.) I hope you can help me!
local part = script.Parent
local function onTouch(hit)
while true do
wait(1)
local e = math.random(1,10)
if e >= 5 then
part.BrickColor = BrickColor.Green()
else
part.BrickColor = BrickColor.Red()
break
end
end
end
part.Touched:Connect(onTouch)
The script is inside a part.

2 comments
When I say its doing what its supposed to do it isnt actually DOING WHAT ITS SUPPOSED TO DO I just mean that its a "Proper script"
Here is a link to how to use a debounce: http://robloxdev.com/articles/Debounce