Getting player pos

I want the code to print the position of the player’s humRP, but it isn’t printing at all. Got the code from another user that said it worked, but it isn’t working for me

--Services
local plr = game:GetService("Players")

--Mainline
plr.PlayerAdded:Connect(function(player) -- when player joins
	player.CharacterAdded:Connect(function(char) -- when the player's character is loaded in
		local humanoidRootPart = char:WaitForChild("HumanoidRootPart") -- wait for HumRP to load in
		while humanoidRootPart do -- while rp loaded in
			print(humanoidRootPart.Position) -- print pos of rp
			wait(4)
		end
	end)
end)

1 Like

why using while humanoidROotPart do when you are already waiting for the HRP to load? try to remove the loop, and if it still doesnt work, try humanoidRootPart.CFrame.Position

1 Like

Removed the while loop: Not work

--Services
local plr = game:GetService("Players")

--Mainline
plr.PlayerAdded:Connect(function(player) -- when player joins
	player.CharacterAdded:Connect(function(char) -- when the player's character is loaded in
		local humanoidRootPart = char:WaitForChild("HumanoidRootPart") -- wait for HumRP to load in
		print(humanoidRootPart.Position) -- print pos of rp
		wait(4)
	end)
end)

Changed to humanoidRootPart.CFrame.Position: Not work

--Services
local plr = game:GetService("Players")

--Mainline
plr.PlayerAdded:Connect(function(player) -- when player joins
	player.CharacterAdded:Connect(function(char) -- when the player's character is loaded in
		local humanoidRootPart = char:WaitForChild("HumanoidRootPart") -- wait for HumRP to load in
		print(humanoidRootPart.CFrame.Position) -- print pos of rp
		wait(4)
	end)
end)

All of the code is in a local script

1 Like

Where is the local script located in?

2 Likes

It works, but it needs to be a server side Script, not a LocalScript.

Also, you should remove the loop - or make it so that it terminates when the character resets. It basically recreates another loop each time and you end up with a mem leak.

2 Likes

StarterPlayerScripts
image
the script is called GetPlrPos

1 Like

Works, thank you! I will also make sure it terminates when the player resets.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.