How to Fix Level Win System. Teleports and gives badge to player upon touching the hitbox

I don’t know how to fix this simple trophy win system. Issue is with the badge, it wont award the badge but it does teleport the player. I would also appreciate anyone making the script more optimized.

Script:

local hitbox = script.Parent
local BS = game:GetService("BadgeService")
local offset = Vector3.new(0, 2, 0)

hitbox.Touched:Connect(function(hit)
	if hit.Parent.Humanoid then
		local Humanoid = hit.Parent.Humanoid
		local char = hit.Parent
		local plr = game.Players:GetPlayerFromCharacter(char)
		local hrp = char.HumanoidRootPart
		
		BS:AwardBadge(plr.UserId, '3851921246732032')
		
		hrp.CFrame = game.Workspace.SpawnLocation.CFrame + offset
	end
end)

Thank you :smile:

Your id must be a number not a string:

BS:AwardBadge(plr.UserId, 3851921246732032)

and for the optimization:

local hitbox = script.Parent
local BadgeService = game:GetService("BadgeService")
local offset = Vector3.new(0, 2, 0)
local badgeId = 3851921246732032

function onHit(hit)
    if hit.Parent:FindFirstChildOfClass("Humanoid") then
        local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if player then
            BadgeService:AwardBadge(player.UserId, badgeId)
            
            local hrp = hit.Parent:FindFirstChild("HumanoidRootPart")
            if hrp then
                hrp.CFrame = game.Workspace.SpawnLocation.CFrame + offset
            end
        end
    end
end

hitbox.Touched:Once(onHit)

Change

BS:AwardBadge(plr.UserId, '3851921246732032')

to

BS:AwardBadge(plr.UserId, 3851921246732032)

Explanation, badgeId (the second passed parameter in AwardBadge) requires a number integer value. You passed a string value.
Read more here: BadgeService#AwardBadge

:smiling_face_with_tear: always one step ahead

characters lol

my bad homie :sob:

idkkk

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