How can I make my script debounce local?

  1. What do you want to achieve? Keep it simple and clear!

Hi devs :wave: ! Ive been trying to make my script which clone a gui with a debounce locally because I don’t want the same player to prompt the gui two times.

  1. What is the issue? Include screenshots / videos if possible!

I can’t find out I can make a debounce local in my type of script

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Didn’t find anything really for my case on the developer hub and I can’t really manage to understand how we can debounce locally

Hope anyone can help :smile: ! Heres the script if someone wanna look into it

local debounce = false

script.Parent.Touched:Connect(function(part)
	if part.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(part.Parent)
		if (not debounce) then
			debounce = true
			print("yay")
			script.Parent.loadingscreen:Clone().Parent = player.PlayerGui
			wait(3)
			debounce = false
			
			
		end

		
	end
end)

If this is server script, then you should make instead of debounce something with tables., because this debounce would be for all players. Try this:

local PlayersDebounce = {}
script.Parent.Touched:Connect(function(part)
	if part.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(part.Parent)
		if not table.find(PlayersDebounce, player.Name)then
			table.insert(PlayersDebounce, player.Name)
			print("yay")
			script.Parent.loadingscreen:Clone().Parent = player.PlayerGui
			wait(3)
			PlayersDebounce[player.Name] = nil		
		end		
	end
end) -- I did not test this script

If you want the player to not be able of activating it again before the Gui becomes invisible, then change this:

            wait(3)
			PlayersDebounce[player.Name] = nil	

To this:

spawn(function()
   repeat 
       task.wait(0.1)
   until player.PlayerGui[script.Parent.loadingscreen.Name].Enabled == false
   PlayersDebounce[player.Name] = nil	
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.