I have two buttons which teleport you to areas as the title says but if the player is quite far away from the teleport destination, the player gets instantly killed. I do not know why this happens. How can I make sure this does not happen. The code:
I think it’s the fact that you’re CFraming the HumanoidRootPart so far and so quick that it’s removing the Head weld and killing the character. Have you tried MoveTo?
Can you provide a video for us? Maybe it will help. I don’t think that teleportation will remove the head weld, so this may not be a problem with the teleportation script. Do you have some other scripts that would possibly kill the player?
(Tbh I don’t even know what magical force is binding the player’s head and body together XD)
EDIT:
You should always absolutely not use MoveTo to teleport a character. The roblox documentations states that you should always use CFrame for teleportation.
I think i know, is it in a local script?
If so you need to change it to a server script, i tried that before in a local script and it also made the player die instanstly.
-- Script
local Players = game:GetService("Players")
local teleport = game.ReplicatedStorage:WaitForChild("Teleport")
local function teleport(player)
teleport:FireClient(player)
end
local function tele(player)
local button = player.PlayerGui.MainGui.Teleporters.Frame.Portals
button.MouseButton1Click:Connect(teleport)
end
--Local Script
local function onWelcomePlayerFired()
game.Players.LocalPlayer.character.HumanoidRootPart.CFrame = CFrame.new(-163.25, 7.113, -20.75)
end
teleport.OnClientEvent:Connect(onWelcomePlayerFired)
You shouldn’t use FireClient in the normal script, instead, the other way round. Fire the server in a localscript, then bind a function to the event server-side to teleport the player.
You can’t teleport a player on the client, its the other way around mate, and also in the local script you should define the gui button there and make it fire the server in the local script.