The entire script shown below works fine except the last part. It is supposed to return the parts color back to what is was before being changed to black. The confusing thing is that it works sometimes but other times it will immediately turn back to black. No error messages are shown in the output. Any insight would be appreciated.
-- whoever touches the part gets put on fire, a black color applied to them, then has damage dealt to them. after 5 seconds the fire is removed and after 1 second the skin tone is returned back to normal
local trap = script.Parent
local dmg = 5
local function onTouch(objectTouched)
print("Something touched the trap")
local color = objectTouched.BrickColor
local fire = Instance.new("Fire")
local person = objectTouched.Parent
local human = person:FindFirstChildWhichIsA("Humanoid")
if ( human ) then
fire.Parent = objectTouched
objectTouched.BrickColor = BrickColor.new(0, 0, 0)
human.Health = human.Health - dmg
wait(5)
objectTouched.Fire:Destroy()
wait(1)
objectTouched.BrickColor = color
end
end
trap.Touched:Connect(onTouch)

1 comment
debounces should fix the issue