I’m currently creating the teleport script.
I am making the script that teleports the player after they died.
But the error don’t appears and I can not find any bugs from them.
Player dies but doesnt teleport.
There is already player local at upper.
button1.MouseButton1Down:Connect(function()
teleportframe.Visible = false
local humanoidrootpart = player.Character:FindFirstChild("HumanoidRootPart")
if humanoidrootpart then
local char = player.Character
local h = char:WaitForChild("Humanoid")
h.Health = 0
wait(8)
humanoidrootpart.CFrame = CFrame.new(part1.CFrame.p) + Vector3.new(0,5,0)
end
end)
Yes. I am making this teleport system for my train game, and when they are on the train they are going to welded to train so I have to kill the player before they get teleport. if I didnt train will be teleported too.
The problem is that you’re not changing the reference for humanoid root part. Also, killing them is rather inefficient, should just reload their character. The below code should work:
button1.MouseButton1Down:Connect(function()
teleportframe.Visible = false
local humanoidrootpart = player.Character:FindFirstChild("HumanoidRootPart")
if humanoidrootpart then
player:LoadCharacter()
local char = player.Character or player.CharacterAdded:Wait()
humanoidrootpart = char:WaitForChild("HumanoidRootPart")
humanoidrootpart.CFrame = CFrame.new(part1.CFrame.p) + Vector3.new(0,5,0)
end
end)
I tried out with the new script to the old script, but it seems like there is a bug. I didn’t see a error but when I pressed the button the ui visibility will be turned off but the player didn’t die and didn’t get teleported.
All deaths &/or player reloads will clear the UI or reset them. Would be best to set them to not reset on spawn. CFrame.new(part1.CFrame.Position) + CFrame.new(0, 5, 0) would also be the best way to define the teleport line.
If you want the best method to do it, make an iterating loop that finds all welds that attach the character to the train and destroy them before teleporting the player. No need for respawn.
LoadCharacter has to be called by the server. I’d suggest adding a remote event that gets fired to the server and the server just has code like:
(remote event).OnClientEvent:Connect(function(plr)
plr:LoadCharacter()
local char = plr.Character or player.CharacterAdded:Wait()
humanoidrootpart = char:WaitForChild("HumanoidRootPart")
humanoidrootpart.CFrame = CFrame.new(part1.CFrame.p) + Vector3.new(0,5,0)
end)
Be sure to define part1 on the server side as the part you want, or fire it in the event as an argument
Remote events do not require a player to be passed as a value if firing from the client, as the first argument is always the player who fired the server event.