Player CFrame Not Changing

Hello! I’m working on a checkpoint system for my game, but I seem to be having a problem where the player’s CFrame is not changing whenever they respawn. I’m not getting any errors so I’m not sure why this is happening. If anyone could help that would be great.

Script:

player.CharacterAdded:Connect(function(char)
    local model = folder:FindFirstChild(level.Value)
    if model then
        print(model.Hitbox.CFrame) -- It is printing this, but CFrame doesnt change
        char:WaitForChild("Torso").CFrame = CFrame.new(model.Hitbox.Position)
    end
end)

try setting the CFrame of the players HumanoidRootPart instead of their torso

This doesn’t work either for some reason

Try this:

player.CharacterAdded:Connect(function(char)
    local model = folder:FindFirstChild(level.Value)
    if model then
        print(model.Hitbox.CFrame) -- It is printing this, but CFrame doesnt change
        char:MoveTo(model.Hitbox.Position)
    end
end)

ok, im guessing this is a local script, try using a remote event to tell the server to change the CFrame of their HumanoidRootPart

also this wont work very smoothly and will end up making the player move way to high in some situations and its much better to use Model | Roblox Creator Documentation

It isn’t in a local script and Model:SetPrimaryPartCFrame still doesnt work

wait i see your problem, you need to set it to the hitboxes CFrame instead of its Position

This still doesnt work it just respawns me at 0,0.

Have you tried waiting a few seconds before setting the player’s position?

Edit: added comments to help with clarity of code.
Edit2: fixed a typo for potential people viewing this in the future

Try adding a RunService Heartbeat wait before setting the CFrame. Sometimes the parts exist but they have not been completely initialized yet which can override your CFrame change.

local RunService = game:GetService("RunService") -- get run service

player.CharacterAdded:Connect(function(char)
    local model = folder:FindFirstChild(level.Value)
    if model then
        print(model.Hitbox.CFrame) -- your debug code
        local torso = char:WaitForChild("Torso")
        RunService.Heartbeat:Wait() -- wait for the parts to initialize by waiting a physics step
        Torso.CFrame = CFrame.new(model.Hitbox.Position) -- now change the parts cframe
    end
end)
3 Likes

Thanks! This works. I’ll keep this in mind in case I have similar problems in the future!

1 Like