Hi. So, what I’m trying to do is make a wall that pulses when you touch it, but when I touch it the wall keeps pulsing which I only want it to pulse once. Heres the code
script.Parent.Touched:Connect(function()
while wait(0.5) do
script.Parent.Transparency = script.Parent.Transparency - 0.1
wait(0.8)
if script.Parent.Transparency == 0.5 or script.Parent.Transparency < 5 then
while true do
script.Parent.Transparency = script.Parent.Transparency + 0.1
wait(0.8)
if script.Parent.Transparency == 1 or script.Parent.Transparency > 1 then
break
end
end
elseif script.Parent.Transparency == 1 or script.Parent.Transparency > 1 then
break
end
end
end)
I believe this is what you are looking for. It would’ve been hard to explain, so I hope you do not mind this.
local part = script.Parent
local pulseStart = 0.5 --any value that would be the transparency of the part
local pulseEnd = 0 --any value as well
local debounce = false --use debounce, to control the event from firing TOO many times
local alreadyPulsed = false
local function pulse()
for i = 0, pulseStart, 0.1 do
part.Transparency = i
wait(0.25)
end
wait(0.5)
for i = (part.Transparency), pulseEnd, -0.1 do
part.Transparency = i
wait(0.25)
end
alreadyPulsed = true --to only make the part pulse once
wait(0.25)
end
part.Touched:Connect(function()
if not debounce then
debounce = true
if alreadyPulsed == false then
pulse()
end
wait(1)
debounce = false
end
end)
part.TouchEnded:Connect(function()
alreadyPulsed = true
end)
Edit: I would recommend not using :Touched() events since I find them a bit awkward to work with. An alternative would be to use magnitude distances (for circular regions only). But if you really need them you may as well use them.