To stop this annoying message that spams my console and literally make a lag in my game.
*Script that gives badge
- Script
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)
local deb = false
script.Parent.Touched:Connect(function(part)
if part.Parent:FindFirstChild('Humanoid') then
if deb == false then
local player = game.Players:GetPlayerFromCharacter(part.Parent)
wait()
game:GetService("BadgeService"):AwardBadge(player.UserId, 2124586648)
deb = true
end
end
end)
But if the Humanoid touches the Scripted Part it’ll keep firing and checking if they have the Badge.
Wouldn’t it be better to have the debounce with the check as well?
You will need to make much more “advanced debounce” for it, because this will stop all players from “checking”. And btw the touch event will still fire no matter what.
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local Player = game.Players.LocalPlayer
local OnCharacterAdded = true -- Choose
local badgeID = 2124586648
local OwnBadge = BadgeService:UserHasBadgeAsync(Player.UserId, badgeID)
script.Parent.Touched:Connect(function(part)
if OwnBadge == true then
if OwnBadge == false then
if part.Parent:FindFirstChild('Humanoid') then
local player = game.Players:GetPlayerFromCharacter(part.Parent)
wait()
game:GetService("BadgeService"):AwardBadge(player.UserId, 2124586648)
end
end
end
end)
local BadgeService = game:GetService("BadgeService")
local Debounce = false
script.Parent.Touched:Connect(function(part)
if Debounce then return end
Debounce = true
if part.Parent:FindFirstChildWhichIsA('Humanoid') then
local player = game.Players:GetPlayerFromCharacter(part.Parent)
--Check if they own the Badge
if BadgeService:UserHasBadgeAsync(player.UserId, BadgeId) then
return
end
--Else award them the badge
BadgeService:AwardBadge(player.UserId, 2124586648)
end
wait(1)
Debounce = false
end)
If you really want the debounce then do following:
local DebounceArray = {}
script.Parent.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChildOfClass("Humanoid") then
if not table.find(DebounceArray,Hit.Parent.Name) then
table.insert(DebounceArray,Hit.Parent.Name)
--do the check for badge
else
return
end
end
end)
Not sure why everyone is saying you should use a debounce… that’s not a viable solution.
You are receiving this error because Roblox is attempting to award a badge to someone who already has it, the way to remedy this is to use an if statement in combination with BadgeService:UserHasBadgeAsync.