Player Is Not Teleporting

I wanted to make a script the reloads the character then teleports him back to his old position, but it does not work can anyone help?

local ReloadPlayer = game.ReplicatedStorage:WaitForChild("ReloadPlayer")

ReloadPlayer.OnServerEvent:Connect(function(player)
	local char = player.Character
	local hrp = char.HumanoidRootPart
	local oldPosition = CFrame.new(hrp.CFrame.X, hrp.CFrame.Y, hrp.CFrame.Z)
	player:LoadCharacter()
	wait(3)
	hrp.Position = oldPosition.Position
end)

Thanks!

Try this.

local ReloadPlayer = game.ReplicatedStorage:WaitForChild("ReloadPlayer")

ReloadPlayer.OnServerEvent:Connect(function(player)
	local char = player.Character
	local hrp = char.HumanoidRootPart
	local oldPosition = CFrame.new(hrp.CFrame.X, hrp.CFrame.Y, hrp.CFrame.Z)
	player:LoadCharacter()
	wait(3)
	char = player.Character
	hrp = char.HumanoidRootPart
	hrp.Position = oldPosition.Position
end)

(Edited)

Try to wait for the character, use this

local ReloadPlayer = game.ReplicatedStorage:WaitForChild("ReloadPlayer")

ReloadPlayer.OnServerEvent:Connect(function(player)
	local char = player.Character or player.CharacterAdded:Wait()
	local hrp = char.HumanoidRootPart
	local oldPosition = CFrame.new(hrp.CFrame.X, hrp.CFrame.Y, hrp.CFrame.Z)
	player:LoadCharacter()
	wait(3)
	char = player.Character
	hrp = char.HumanoidRootPart
	hrp.Position = oldPosition.Position
end)

If you’re just doing this to update appearance, then you should just re-apply the player’s humanoid description;

local ReloadPlayer = game.ReplicatedStorage:WaitForChild("ReloadPlayer")
local PlayersService = game:GetService("Players")

ReloadPlayer.OnServerEvent:Connect(function(player)
    local success, err = pcall(function() -- prevent unforeseen errors from occurring 
        local HumanoidDescription = PlayersService:GetHumanoidDescriptionFromUserId(player.UserId)
        player.Character.Humanoid:ApplyDescription(HumanoidDescription)
    end) 
end)

However if that is not your intention, then you should do;

local ReloadPlayer = game.ReplicatedStorage:WaitForChild("ReloadPlayer")

ReloadPlayer.OnServerEvent:Connect(function(player)
    if player.Character ~= nil and player.Character:FindFirstChild("Humanoid") then
        local OldCFrame = player.Character.Humanoid.RootPart.CFrame
        player:LoadCharacter()
        local TimePast = 0
        repeat
        task.wait(1)
        TimePast = TimePast + 1
        until player.Character ~= nil and player.Character:FindFirstChild("Humanoid") or TimePast == 11
        if TimePast < 11 then
            player.Character:SetPrimaryPartCFrame(OldCFrame)
        end
    end
end)

This will give the character a maximum of 10 seconds to properly load in before teleporting them.

All of them work so Thanks But I just used the first one as solution.

1 Like