I tried asking this yesterday but I didn't get a good response so I'm asking it again.
Here is my script:
function onTouch(part) local humanoid = part.Parent:FindFirstChild("Humanoid") if script.Parent.Transparency == 0 then if (humanoid ~= nil) then humanoid.Health = 0 end end end while true do script.Parent.Transparency = script.Parent.Transparency + 0.5 wait(0.5) script.Parent.Transparency = script.Parent.Transparency + 0.5 wait(1) script.Parent.Transparency = 0 wait(1.5) end script.Parent.Touched:Connect(onTouch)
Make sure you are using a server script and not a local script. You cannot run a loop and wait for another part of code to run at the same time. The loop will continue to run and wont be able to check to see if it was touched. Use a stepped function instead, using increments per second as a basis to fade in and out.
function onTouch(part) print(part) local humanoid = part.Parent:FindFirstChild("Humanoid") if humanoid == nil then humanoid = part.Parent.Parent:FindFirstChild("Humanoid") end if script.Parent.Transparency <= 0 then if (humanoid ~= nil) then humanoid:TakeDamage(100) end end end local RunService = game:GetService("RunService") local RATE_PER_SECOND = .5 local fadein = false local waittime = 0 RunService.Stepped:Connect(function(time, step) local increment = RATE_PER_SECOND * step if fadein == false then script.Parent.Transparency = script.Parent.Transparency + increment if script.Parent.Transparency >= 1 then waittime = waittime + increment if waittime >= .5 then -- Adds .5 every second, so if you want to wait 1 second wait till .5, 2 seconds woulkd be waittime >= 1. 1.5 seconds would be waittime >= .75 fadein = true waittime = 0 end end else script.Parent.Transparency = script.Parent.Transparency - increment if script.Parent.Transparency <= 0 then waittime = waittime + increment if waittime >= .5 then fadein = false waittime = 0 end end end end) script.Parent.Touched:Connect(onTouch)
function onTouch(part) local humanoid = part.Parent:FindFirstChild("Humanoid") if (humanoid ~= nil) then -- if a humanoid exists, then humanoid.Health = 0 -- damage the humanoid end end function onTouch(part) local humanoid = part.Parent:FindFirstChild("Humanoid") script.Parent.Touched:connect(onTouch) if script.Parent.Transparency == 1 then if (humanoid ~= nil) then humanoid.Health = 100 end end end