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

i need help debouncing a code that checks the players backpack and idk the position to put it?

local hi = false
local keycard = "Keycard"
script.Parent.Touched:Connect(function(hit)
  local character = hit.Parent
  local player = game.Players:GetPlayerFromCharacter(character)
  if player then
    local backpack = player.Backpack
     if backpack:FindFirstChild(keycard) or character:FindFirstChild(keycard) then
	if not hi then
		hi = true
	print("opendoor")
	wait(.5)
	  tweenEopen:Play()
wait(10.6)
hi = false
end

1 comment

0

this might get me banned but i cant do it

1 answer

Try to locate the Debounce outside of the if statement, and make it close to the start and end as possible (Bad english alert lol)

local Debounce = false
local keycard = "Keycard"
script.Parent.Touched:Connect(function(hit)
if not De then
  De = true
  local character = hit.Parent
  local player = game.Players:GetPlayerFromCharacter(character)
  if player then
    local backpack = player.Backpack
     if backpack:FindFirstChild(keycard) or character:FindFirstChild(keycard) then
    print("opendoor")
    wait(.5)
      tweenEopen:Play()
wait(10.6)
De = false
end

4 comments

0

what does de do

0

'de' is the debounce

0

hi is the debounce

0

I edited

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