Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Attempting to teleport the player to a part after they respawn?

I'm scripting an obby and I'm having an issue with the code. Each checkpoint is numbered so it is equivalent to the "leaderstats.Stage" value. The code is meant to take the value and teleport the player there but won't work.

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		char:SetPrimaryPartCFrame(workspace:FindFirstChild(player.leaderstats.Stage.Value).CFrame)
    end)
end)

1 comment

0

It's not working because it's not possible to get the CFrame of a Value, hope this helps.

1 answer

You are referencing the player with the variable plr. However, you are using the wrong variable when teleporting the player. You only need to replace player.leaderstats.Stage.Value with plr.leaderstats.Stage.Value

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
		local HumanoidRootPart = char:WaitForChild("HumanoidRootPart") -- Just an edit to ensure that the HumanoidRootPart exists before teleporting.
        char:SetPrimaryPartCFrame(workspace:FindFirstChild(plr.leaderstats.Stage.Value).CFrame) -- You are using "player". Wich is nil due to you using the "plr" variable instead.
    end)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.