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

Im not sure on how to add debounce to my script. Can someone please help me out?

Hi, so I just got into scripting and I want to make it so that when I touch a part it gets un anchored and then when I get off it it goes into the same position and gets anchored again. I managed to somehow make this work but the only problem is that when I touch the part it moves it multiple times. I figured that the only way to fix it is by adding debounce. However I have no clue on how to add it. (sorry if the script is a little messy, im really new to scripting so i'm not sure on how to organize it)

Thanks in advance!

local function Func1()
Part = game.Workspace.Part
	print("FUNCTION 1 FIRED")
	print("I WAS STEPPED ON SMH")
	game.Workspace.Part.Anchored = false
	
end

local function Func2()
	print("FUNCTION 2 FIRED")
	print("OK IM GOOD NOW")
	game.Workspace.Part.Anchored = true
	Part.Position = Part.Position + Vector3.new(10,4.5,0)
	
end

game.Workspace.Part.Touched:Connect(Func1)
game.Workspace.Part.TouchEnded:Connect(Func2)

MY SCRIPT

3 comments

0

Use the code block to put scripts in so it looks more understandable

0

oh alright sorry

0

done

1 answer

✓ Accepted answer

Yes you need to,it prevents for overlapping:

Debounce = true
	local Part = game.Workspace.Test1
local function Func1()
	if Debounce then --Checks if state is true
		Debounce = false --Disables it
		 print("FUNCTION 1 FIRED")
		print("I WAS STEPPED ON SMH")
		Part.Anchored = false
		wait(3)
		Debounce = true --Enables it again
	end
end
	 
local function Func2()
	if Debounce then --Same thing
		Debounce = false
		print("FUNCTION 2 FIRED")
		print("OK IM GOOD NOW")
		 Part.Anchored = true
		Part.Position = Part.Position + Vector3.new(10,4.5,0)
		 Debounce = true
	end
	
	end
	 
	
	Part.Touched:Connect(Func1)
	Part.TouchEnded:Connect(Func2)
		

7 comments

0

Also organized it

0

tysm :)

0

np,tell me if you want explanation,and if it helps,mark it as the answer please!

0

Edited it because it was an error i noticed lol

0

@yuni_Boy1234 I added this to my script but for some reason when I touch the part it doesn't say that im touching it and then the script doesn't run.

0

Fixed!

0

Change the part variable to the part you want the script to affect it.REMEMBER change the affected part to another name due to "Part" is the default of all so the script wont recognize which one

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