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)
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
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)