Badge is just given to one player

Hello everyone, I made a badge when you touched it, it appears a GUI, but it seems to just give to the first player that touched, the second one can’t get it

this is the script inside of the brick you touch to get the badge and fire the GUI:


local id = 2128733046

local RS = game.ReplicatedStorage

deb = false

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if deb == false then
			deb = true
			local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
			badgeService:AwardBadge(plr.UserId, id)
			if plr then
				RS["ShowBadgeShower"]:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
			end
		end
	end
end)

and this one is the local script inside the GUI:

	script.Parent.Visible = true
	wait(6)
	script.Parent.Visible = false
end)

Well I hope you can help me to solve this, thank you.

It looks like you forgot to set the deb to false after a certain amount of time. Try changing your code to something like this:

local id = 2128733046

local RS = game.ReplicatedStorage

deb = false

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if deb == false then
			deb = true
			local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
			badgeService:AwardBadge(plr.UserId, id)
			if plr then
				RS["ShowBadgeShower"]:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
			end
            wait(3)
            deb = false
		end
	end
end)

Happens to all of us at times :grin:.

2 Likes

Oh, sorry, you are right!, thank you so much for your time!

1 Like

Hi @BoidInternet_123, sorry it’s me again, I just remember why I just not used debounce, because it appears twice times when you touch the part, I mean the GUI, do you know how can I avoid this?

Did you try adjusting the debounce time (the time inside wait()) to something bigger than 3?

Alternatively you could check if the player already has the badge, if they do, don’t do the shower event. To check if a player has a badge, you can use badgeService:UserHasBadgeAsync().

1 Like

Thank you so much for your time and patience!

1 Like