When a player kills my BossNpc I want them to get a badge for defeating them and immediately teleport to another location but it wont work and im getting no output errors
local BOSS = game.Workspace:FindFirstChild("Boss")
local playerWhoKilledNPC
BOSS.Humanoid.Died:Connect(function()
playerWhoKilledNPC = game.Players:GetPlayerFromCharacter(BOSS.Humanoid)
end)
local function handlePlayerCharacterAdded(player)
player.CharacterAdded:Connect(function(character)
if player == playerWhoKilledNPC then
local newSpawnLocation = Vector3.new(100, 0, 100)
character.HumanoidRootPart.CFrame = CFrame.new(newSpawnLocation)
local badgeId = 2146995625
game:GetService("BadgeService"):AwardBadge(player.UserId, badgeId)
end
end)
end
game.Players.PlayerAdded:Connect(handlePlayerCharacterAdded)