Setting the Player's position

  1. What do you want to achieve?
    When the player dies or joins the game, I need their position to be set to the position of a part in the workspace.

  2. What is the issue?
    Their position is not being set, there are no errors being outputted.

  3. What solutions have you tried so far?
    I can’t find exactly what I’m looking for, if there are any topics already on this and I’ve just not been able to find them then it would be much appreciated if you could link it :slightly_smiling_face:

This is what I’ve tried so far. ServerData[Player].leaderstats.Level is what stage the player is currently on and it’s searching a folder the name to move the HRP to.

This is using Player.CharacterAdded event by the way.

local HRP = Character:WaitForChild("HumanoidRootPart")
		HRP.CFrame = game.Workspace.Checkpoints:WaitForChild(tostring(ServerData[Player].leaderstats.Level)).CFrame

Sorry if this is really simple and has already been asked, I’ve tried to look for some topics relating to this.
Any help is much appreciated!

2 Likes

can you show more of your script?

Try this:

local part = game.Workspace.part -- or wherever the part is

for i, v in pairs (game.Players:GetPlayers()) do
v.Character.HumanoidRootPart.Position = Part.Position
2 Likes

There isn’t much more of use to show. The Level is stored as an Integer, and the part in Checkpoints that it’s looking for is just a part. What do you need to see?

In this case you want to use SetPrimaryPartCFrame on the player.Character. CFrame.new() will be the position of where ever you want the character to go.

1 Like

try setting the respawn point and save it instead of setting and saving your position
Player.RespawnLocation (roblox.com) and use data stores to save your respawn location

Because of using tostring, it must have returned nil value, so you must use tonumber instead.

This doesn’t seem to be working, unless I’m doing this wrong.

Player.Character:SetPrimaryPartCFrame(CFrame.new(game.Workspace.Checkpoints:FindFirstChild(tostring(ServerData[Player].leaderstats.Level)).Position))

Probably just doing something wrong :confused:

But the name of the object I’m looking for is a string, as with all names.

uhh why are you doing :FindFirstChild(tostring(ServerData[Player].leaderstats.Level)).Position))
do

:FindFirstChild(ServerData[Player].leaderstats.Level))).Position

This gives me an error because I’m trying to get the position of the Part I just found. If I put the .Position at the end it’s not getting the Position of anything.

i edited it try again i think its not working because you trying to get a string you have to get an object

Again, I’m only using tostring() to find the part, not get the object. Once I have the object, I am then getting it’s position.

you have to get the object not its name

May I ask what the ServerData object is and what it holds?

I’m finding it using it’s name, turning the ServerData[Player].leaderstats.Level which is an integer into a string to find it.

leaderstats = {
			-- General
			Level = 0,
			Rebirths = 0
		},

		hiddenstats = {
			-- Currency
			Coins = 0,
			Gems = 0,

			-- Tags
			OwnedTags = {},
			EquippedTag = "",

			-- Trails
			OwnedTrails = {},
			EquippedTrail = ""
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
	    local hrp = character:WaitForChild("HumanoidRootPart")
	    local leaderstats = player:WaitForChild("leaderstats")
	    local level = leaderstats:WaitForChild("Level")
	
  	    for i , descendants in pairs(game.Workspace.Checkpoints:GetDescendants()) do
		    if level.Value == descendants.Name then
			    hrp.CFrame = descendants.CFrame + Vector3.new(0, 6, 0)
		    end
	    end
    end)
end)

it is not going to work that way you probably have to use a for loop

local checkpoint
for i, v in pairs(workspace:getChidren()) do
    if v.name = "" then
        checkpoint = v
    end
end

This also isn’t working, no errors in output.