I tested this and it's working but, I'm assuming you are trying to make it slightly invisible and uncollideable then after a period of time it goes back to normal right?
Then you need to add debounce! To prevent multiple action while one is running.
The reason it doesn't work as it supposed to do is because when you try to go through the door, your character will be touching the part and runs your touched event.
local delay = 7
local deb = false
script.Parent.Touched:Connect(function(hit)
if deb == false then
deb = true
if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
script.Parent.Transparency = 0
wait(1)
script.Parent.Transparency = 0.3
wait(1)
script.Parent.Transparency = 0.7
script.Parent.CanCollide = false
wait(delay)
script.Parent.Transparency = 0.7
wait(1)
script.Parent.Transparency = 0.3
wait(1)
script.Parent.Transparency = 0
script.Parent.CanCollide = true
wait(.25)
deb = false
end
end
end)
FYI:
You can use for i loop to change transparency of your part, etc for a smooth effect. Example:
local delayTime = 7
local deb = false
script.Parent.Touched:Connect(function(hit)
if deb == false then
deb = true
if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
for i = 1, 10, 1 do
script.Parent.Transparency = i * 0.1
wait()
end
script.Parent.CanCollide = false
wait(delayTime)
for i = 1, 10, 1 do
script.Parent.Transparency = 1 - i * 0.1
wait()
end
script.Parent.CanCollide = true
wait(.25)
deb = false
end
end
end)
1 comment
I tried and it doesnt work. Is there a thing wrong?