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

it is spamming visible like true false true false and i want it to be where you hit it once?

how do I make a debounce? Can someone help instead of giving me a script? Like I want to learn. Here is my script

local Debounce = true
script.Parent.Touched:Connect(function()
	game.Workspace.Door.DoorWall.BillBoardGui.BillboardGui.E.Visible = true
end)
local Debounce = true
script.Parent.TouchEnded:Connect(function()
	game.Workspace.Door.DoorWall.BillBoardGui.BillboardGui.E.Visible = false
end)

for some reason when you touch the block it makes the text visible to false then when you move on the platform it turns the visible to true to false every time you move?

2 comments

0

touched and touchended are really oofed in roblox, they don't help much lol

2 answers

i dont know for sure if this works because i didn't test it

but pretty sure this might not work

local debounce = true

script.Parent.Touched:Connect(function(hit)
	if debounce == true then
		debounce = false
		local h = hit.Parent:WaitForChild("Humanoid")
		if h then
			game.Workspace.Door.DoorWall.BillBoardGui.BillBoardGui.E.Visible = true
			wait(2) -- replace '2' for how long you want the 'E' to be visible
			game.Workspace.Door.DoorWall.BillBoardGui.BillBoardGui.E.Visible = false
		end
		wait(2) -- the cooldown for the door pop up
		debounce = true
	end
end)

The purpose of a debounce is to put in a cooldown. In this case you are not changing the value of the debounce. What I would do is to set the debounce equal to false initially, and when the touch event is fired you set it to true. But how would we do this? We would use an if statement to check. If the debounce is equal to false, which means it is usable again set it to true, and insert a wait() statement for however long you want it to wait for then you can put the rest of your code after.

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