so im making an obby and im making a script for a fading part. i thought it would work but it doesnt and now i have no idea how to get it to work.
(fade is an IntValue)
local fade = script.Parent.fade local fadeAmount = 0.05 local fadeTime = 0.5 local part = script.Parent part.Touched:Connect(function(hit) while true do wait(fadeTime) fade.Value = fade.Value + fadeAmount part.Transparency = fade if fade == 1 then part.CanCollide = false end end end)
Hello! Here is how to fix it:
local fadeAmount = 0.05 local fadeTime = 0.05 local part = script.Parent local debounce = false part.Touched:Connect(function(hit) if debounce == false and hit.Parent:FindFirstChild("Humanoid") then debounce = true -- Can't touch multiple times repeat wait(fadeTime) script.Parent.Transparency = script.Parent.Transparency + fadeAmount until script.Parent.Transparency >= 1 --Checks if it is bigger than or equal to 1 part.CanCollide = false --Turns off CanCollide wait(2) repeat wait(fadeTime) script.Parent.Transparency = script.Parent.Transparency - fadeAmount until script.Parent.Transparency <= 0 debounce = false part.CanCollide = true end end)
I tested it, and it works, basically, your problem was that you put a while true do loop. Hope it helps =D