Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What did I do wrong?

I have a feeling that I know what's wrong but I'm not sure. Can someone take a look at it and tell me how to fix it?

while true do	

function touch()
	
	for i=1,3 do
		
		script.Parent.Transparency=0.3
		
		wait(0.8)	
	
	end
	
	script.Parent.CanCollide = false
	wait(3)
	script.Parent.CanCollide = true

end

script.Parent.Touched:connect(touch)

Thank you.

2 answers

✓ Accepted answer

I think this is what you want!

debounce= false -- Variable to say if it's running or not

script.Parent.Touched:connect(function()
	if debounce == false then - Check if already running
		debounce = true -- Tell the script is being run
		for i=0,1,0.1 do -- Start fading away
			script.Parent.Transparency = i -- Transparency up by 0.1
			wait(0.25)
		end
		script.Parent.CanCollide = false -- They'll fall through now >:)
		wait(1) -- Wait 1 second...
		for i=1,0,-0.1 do -- Start fading back
			script.Parent.Transparency = i -- Transparency down by 0.1
			wait(0.25)
		end
		script.Parent.CanCollide = true -- They wont fall through now :(
		debounce = false -- Tell the script it's finished
	end
end)

First thing first, your main problem.

You forgot an end at then very end of your script. But you should put the new end in line 20.

But that would crash studio, for it runs too fast.

replace while true do with while wait() do .

even though the while wait is not needed.

And you may want to reorder the script a bit, but I did it for you.

debounce=false

script.Parent.Touched:connect(function(hit)

if not debounce then
debounce=true
for i=1,5 do
        script.Parent.Transparency=script.Parent.Transparency+0.2
wait(.1)
end
      



    script.Parent.CanCollide = false
    wait(3)
    script.Parent.CanCollide = true

for i=1,5 do
        script.Parent.Transparency=script.Parent.Transparency-0.2
wait(.1)
end
wait(1)
debounce=false
end
end)



hope I helped!

Chemz

This discussion is preserved as it was. New answers, comments, and votes are closed.