Teleporting player not working

Hello! I am making a script which makes the player spawn at a certain spawnpoint depending on the players stage value. I have looked at the devforum and could not find anything since I did not get any errors. Here is the script:

game.Players.PlayerAdded:Connect(function(player)
	local ldr = Instance.new("Folder", player)
	ldr.Name = "leaderstats"
	
	local stage = Instance.new("IntValue", ldr)
	stage.Name = "Stage"
	stage.Value = 1
	
	--|| Player died ||--
	
	player.CharacterAdded:Connect(function(char)
		local stage = "Stage"..player:WaitForChild("leaderstats").Stage.Value
		local spawnDestination = game.Workspace[stage]:WaitForChild("Spawn")
		
		local hrp = char:FindFirstChild("HumanoidRootPart")
		print(hrp)
		if hrp then
			hrp.CFrame = spawnDestination.CFrame
		end
	end)
end)

I printed out the humanoidrootparts cframe and spawndestination cframe before and after assigning it. This is what I got:


Seems like I am changing the humanoidrootparts cframe but the player isnt moving…

I’ve tried to use player.Cframe = () but didn’t work too I suggest using a remote event thats what I did and worked perfectly.

1 Like

The script shown above is a server script so you mean bindable event right? Or did I make a mistake by having the script in a server script rather than it being a local script?

1 Like

But you cant have the “game.Players.PlayerAdded” function in local scripts and the script above runs for each player individually since thats how the function works. I updated my topic so now you should be able to see the whole script

Where is you’re script located?

image
It is the stats script

Alright, so I see it’s changing the humanoid cframe which means it is working so I’m not honestly sure whats the problem rn.

It is changing it but the player isnt moving to that desired position.

I’m gonna assume it’s a studio bug.

Try using char:SetPrimaryPartCFrame(spawnDestination.CFrame)

Using the parameter char is quite finicky for some reason, instead locate the player within workspace then teleport

--using the player parameter
player.Character.HumanoidRootPart.CFrame = spawnDestination.CFrame + Vector3.new(0,1,0)

or

--locating the player from workspace use name.
game.Workspace[player.Name].HumanoidRootPart.CFrame = spawnDestination.CFrame + Vector3.new(0,1,0)

(if you don’t need the vector 3 then you don’t need it)
also may need to waitforchild on humanoid root part

2 Likes

I will try this when I get back home. Thanks though