Typelnt
(I_I)
August 20, 2022, 7:11am
#1
As you can see from the topic I want to teleport the character to a specific part as player dies
What do I want to achieve? I want to teleport the character to a specific part as player dies
What’s the issue? it not working and the character is spanning in the spawn point
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 : 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 !
have a nice day !
4 Likes
Typelnt
(I_I)
August 20, 2022, 7:16am
#3
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 !
3 Likes
Typelnt
(I_I)
August 20, 2022, 7:18am
#5
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 !
3 Likes
Typelnt
(I_I)
August 20, 2022, 7:20am
#7
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 !
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
Typelnt
(I_I)
August 20, 2022, 7:22am
#10
I was also replaying about it xd
5 Likes
Typelnt
(I_I)
August 20, 2022, 7:26am
#11
Didn’t work
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
drilinz
(drilinz)
August 20, 2022, 7:29am
#14
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
Typelnt
(I_I)
August 20, 2022, 7:30am
#16
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
Typelnt
(I_I)
August 20, 2022, 7:32am
#19
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
aliaun125
(David)
August 20, 2022, 7:33am
#20
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