How to stop the we already gave out the badge everytime?

im having an bug or big lags when someone wins or touched the part how do i stop spamming the message of we already gave out the badge.

Scripts :

script.Parent.Touched:Connect(function(part)
	if part.Parent:FindFirstChild('Humanoid') then
		local player = game.Players:GetPlayerFromCharacter(part.Parent)
		game:GetService("BadgeService"):AwardBadge(player.UserId, 2124586648)
	end
end)

I think you need use a data store for badges.

Use the UserHasBadgeAsync function to check if the user who stepped on the part has the badge

2 Likes

Maybe use debounce if it works with badges?

local debounce = false
script.Parent.Touched:Connect(function(part)
	if part.Parent:FindFirstChild('Humanoid') then
		local player = game.Players:GetPlayerFromCharacter(part.Parent)
		game:GetService("BadgeService"):AwardBadge(player.UserId, 2124586648)
if  not debounce then
debounce = true
wait(2)
debounce = false
	end
end
end)

I cannot use debounce because it will not allow other to get the badge.

But there’s a wait to set it back to false.

Yah i know but what if they try again to touch the part wherein they can get the badge it still spams right?

No, not exactly since the touch event will fire again and it will fire the debounce.

Use the UserHasBadgeAsync?

script.Parent.Touched:Connect(function(part)
	if part.Parent:FindFirstChild('Humanoid') then
		
		local player = game.Players:GetPlayerFromCharacter(part.Parent)
		
		
		if game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, 2124586648) then
			--Nothing, you got the badge already.
		else
			game:GetService("BadgeService"):AwardBadge(player.UserId, 2124586648)
		end

	end
end)

This will probably work

4 Likes

Here, instead of having an empty space, you could use not to shorten it, like

		if not game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, 2124586648) then
			game:GetService("BadgeService"):AwardBadge(player.UserId, 2124586648)
		end
1 Like