Why won't my teleportation script work?

I want to create a script that teleports you to a part in the spectator area after you die. However, when my character dies, they don’t teleport to the spectator area after they spawn, nor does roblox studio present any syntax errors. I tried different condition statements but they didn’t function together like the code I have currently. Can anyone see what I messed up on?

wait()	

local Humanoid = script.Parent.Humanoid

local function go(player)	
	player.Character.HumanoidRootPart.CFrame = CFrame.new(part.Position + Vector3.new(0, 3, 0))
end

Humanoid.Died:Connect(function()
	wait(5.02)
	go()
end)

This will never work because this script is a child of the player’s character. When the player dies it will just be destroyed. Put this script in ServerScriptService:

local part = --define here

game.Players.PlayerAdded:Connect(function(player)
      player.CharacterAdded:Connect(function()
             player.Character.HumanoidRootPart.CFrame = CFrame.new(part.Position + Vector3.new(0,3,0))
      end)
end)
2 Likes

Adding onto the above post, you’ll also need to add a check to make sure if the player has died or not since CharacterAdded will fire the event time a Character Model is added onto the workspace, so it’d teleport all characters that get added

local part = --define here

game.Players.PlayerAdded:Connect(function(player)
    local Dead = false 
    player.CharacterAdded:Connect(function(character)
        local Humanoid = character:WaitForChild("Humanoid")
        if Dead == true then
           character.HumanoidRootPart.CFrame = CFrame.new(part.Position + Vector3.new(0,3,0))
        end
        Humanoid.Died:Connect(function()
            Dead = true
        end)
    end)
end)

I swear I flippin fixed my post idk why it didn’t work

1 Like