How can I teleport a character to a specific part?

As you can see from the topic I want to teleport the character to a specific part as player dies

  1. What do I want to achieve? I want to teleport the character to a specific part as player dies

  2. What’s the issue? it not working and the character is spanning in the spawn point

  3. What solutions have I tried so far? I have looked in Devform but didn’t found any related topic

My code is given below:

 Players.PlayerAdded:Connect(function(player)
	local chr = player.Character or player.CharacterAdded:Wait()
	chr:WaitForChild("Humanoid").Died:Connect(function()
		chr.HumanoidRootPart.CFrame = CFrame.new(game.Workspace.spawn.Position)
	end)
end)

The part is : image and it is parented to workspace

4 Likes

I think you made only a little mistake :

Players.PlayerAdded:Connect(function(player)
	local chr = player.Character or player.CharacterAdded:Wait()
	chr:WaitForChild("Humanoid").Died:Connect(function()
		chr.HumanoidRootPart.CFrame = CFrame.new(game.Workspace.spawn.CFrame)
	end)
end)

I hope that was helpful ! :grin:
have a nice day ! :yum:

4 Likes

ops my bad there is a position on code wait let me edit post

4 Likes

Ok, but I think there is the same problem, because to set a CFrame you need a CFrame, open the output and you will see an error ! :smile:

3 Likes

When I put CFrame “ServerScriptService.Join Handle:29: invalid argument #1 to ‘new’ (Vector3 expected, got CFrame)”

4 Likes

It is what I explain to you !
Replace your script by my script !
It will work ! :wink:

3 Likes

Bruh CFrame.new need vector 3 not a CFrame
and if i had to follow your code I need to edit it into this

chr.HumanoidRootPart.CFrame = game.Workspace.spawn.CFrame
4 Likes

If youre using a pre-existing CFrame, there shouldnt be any purpose creating a new CFrame.
Instead, just do

character.PrimaryPart.CFrame = workspace.spawn.CFrame
4 Likes

Yes, your right ! :smile:
Thank you for the help !
so he should do that :

Players.PlayerAdded:Connect(function(player)
	local chr = player.Character or player.CharacterAdded:Wait()
	chr:WaitForChild("Humanoid").Died:Connect(function()
		chr.HumanoidRootPart.CFrame = game.Workspace.spawn.CFrame
	end)
end)
3 Likes

I was also replaying about it xd

5 Likes

Didn’t work :confused:
Ignore this: dslghlkcxvneoir dsihkjfbfkdjg

4 Likes

Oh sorry it doesn’t work, im stupid …
I haven’t test but now i can help you with studio !

3 Likes

If that doesnt work, instead try this in a LocalScript, parented to StarterCharacterScripts:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

Character:WaitForChild("Humanoid").Died:Connect(function()
	Character.PrimaryPart.CFrame = workspace.spawn.CFrame
end)
4 Likes

Change it to this:

 Players.PlayerAdded:Connect(function(player)
	local chr = player.Character or player.CharacterAdded:Wait()
	chr:WaitForChild("Humanoid").Died:Connect(function()
		chr.HumanoidRootPart.CFrame = game.Workspace.spawn.CFrame
	end)
end)
4 Likes

Yes but it will be easy to cheat the code if we change it to a local script no ?

1 Like

I have already tried it and it didn’t work

3 Likes

Since its using no RemoteEvents, hacking that script wont be possible. The only thing hackers could do with that is steal the code.

2 Likes

I think the issue is the spawn have a more important situation !
So instead to teleport the player to the other part he go into the real spawn !

1 Like

the same code is working from the server script I put the same code as above for tp instead of firing on died it fire when player joins and it works perfectly

2 Likes

The died event instantly triggers after the player died, changing the cframe of rootpart will not apply to new character.(I think that is ur problem,not sure tho)

3 Likes