Im attempting to give the player a badge when a certain part is clicked, then cloning the weapon into their backpack/startergear. When the code is executed, everything runs except the badge giver.
The badge giver refuses to award the badge.
Here is the code:
local badgeService = game:GetService("BadgeService")
local saberBadgeId = 2124589090
local debounce = false
local saberCollect = game.Workspace.Crossguard.CrossguardCollect
local clickDetect = saberCollect.ClickDetector
local whispers = saberCollect.Whisper
local function awardBadge(player,badgeId)
local success, failure pcall(function()
badgeService:AwardBadge(player.UserId,badgeId)
end)
if not success then
warn("error occured whilst awarding badge: ", failure)
end
end
clickDetect.MouseClick:Connect(function(player)
if debounce then return end
debounce = true
whispers:Play()
wait(5)
whispers:Stop()
if player.Backpack:FindFirstChild"Crossguard Lightsaber" or player.StarterGear:FindFirstChild"Crossguard Lightsaber" then debounce = false return end
awardBadge(player, saberBadgeId)
local x = game.ServerStorage["Crossguard Lightsaber"]:Clone()
local y = x:Clone()
x.Parent = player.StarterGear
y.Parent = player.Backpack
player.Sabers.Crossguard.Value = true
debounce = false
end)
Your syntax is incorrect here. It should be …failure = pcall(function()…
Turns out it runs properly when doing this but it never declares those two variables properly so whatever is in the statement below doesn’t ever execute because Lua assumes you’re creating two empty variables success and failure then running a pcall function right after it, not actually giving them any value, so success and failure would always be nil, hence it would always error and return the error as nothing or nil.