Coordinates script isn't working

I want to make a script that shows the player their position, but it isn’t working while the players is moving and only updates when they stop. Any solutions?

local player = game.Players.LocalPlayer
local textLabel = script.Parent
local chara = player.Character

if not chara then
	chara = player.CharacterAdded:Wait()
end

local hum = chara.Humanoid

hum:GetPropertyChangedSignal("MoveDirection"):Connect(function() 
	local function convertPos()
		local pos = chara.HumanoidRootPart.Position
		local xPos = math.round(pos.X)
		local yPos = math.round(pos.Y)
		local zPos = math.round(pos.Z)
		textLabel.Text = tostring(xPos) .. tostring(yPos) .. tostring(zPos)
	end
    convertPos()
end)

Yeah I was starting to write about that haha. If I may give one suggestion though, it would be a good idea to use string formatting for the numbers, just because sometimes issues can arise just concatenating numbers.

textLabel.Text = string.format("%d:%d:%d", xPos, yPos, zPos)

thanks! but i just encountered another issue… oh well :‌/

What’s the new issue that arose?

the code works as intended except that the position text only updates upon stopping and not every tick the player moves

MoveDirection change when they change direction, not position

detect when they change Position

I think instead of using the MoveDirection, it may be better to use the Running event listener.

humanoid.Running:Connect(function(speed)
	if speed > 0.04 then
		local pos = chara.HumanoidRootPart.Position
		local xPos = math.round(pos.X)
		local yPos = math.round(pos.Y)
		local zPos = math.round(pos.Z)
		textLabel.Text = tostring(xPos) .. tostring(yPos) .. tostring(zPos)
	end
end)

nevermind, I just figured out that if you put the block of code in a while loop it works! =D

local player = game.Players.LocalPlayer
local textLabel = script.Parent
local chara = player.Character

if not chara then
	chara = player.CharacterAdded:Wait()
end

local hum = chara.Humanoid

while hum:GetPropertyChangedSignal("MoveDirection") do
	local function convertPos()
		local pos = chara.HumanoidRootPart.Position
		local xPos = math.round(pos.X)
		local yPos = math.round(pos.Y)
		local zPos = math.round(pos.Z)
		textLabel.Text = tostring(xPos) .. ", " .. tostring(yPos) .. ", " .. tostring(zPos)
	end
	convertPos()
	task.wait()
end

No no no no no, that’s the worst way to go about that.

oh alr I will just use what u said

Yeah because it’s relying on hum:GetPropertyChangedSignal being a truthy value, and is constantly updating the text even if the player’s not moving. It takes up more compute time than what’s necessary.

but I only made it run when the player is detected to be moving, also ur thing didnt work =/

although it doesnt stop running sadly

Does it not update the text when the player’s moving?

it updates it when the player starts moving and when the player stops moving but not between

Ah, alright yeah that makes sense. I think I might have an idea, but it’ll take me a bit to write it out.

its alright, I have 30 mins so it should be ok!

Alright, here we go

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char.Humanoid
local hrp = char.HumanoidRootPart

local isOnTheMove = false
local nonRunningConditions = {
	[Enum.HumanoidStateType.Landed] = true,
	[Enum.HumanoidStateType.PlatformStanding] = true,
	[Enum.HumanoidStateType.Dead] = true,
	[Enum.HumanoidStateType.None] = true
}

hum.StatedChanged:Connect(function(_, currentState)
	if not nonRunningConditions[currentState] and not isOnTheMove then
		isOnTheMove = true
		while isOnTheMove do
			local pos = hrp.Position
			local xPos = math.round(pos.X)
			local yPos = math.round(pos.Y)
			local zPos = math.round(pos.Z)
			textLabel.Text = string.format("%d:%d:%d", xPos, yPos, zPos)
			task.wait(1/33.333)
		end
	else
		isOnTheMove = false
	end
end)

What this’ll do is listen for when the humanoid’s state changes, sees if they’re running and updates the text until the condition is no longer running. It might require some tinkering though.

https://create.roblox.com/docs/reference/engine/classes/Humanoid#StateChanged
https://create.roblox.com/docs/reference/engine/enums/HumanoidStateType

Edited so that it instead excludes actions where the player doesn’t normally move.

Thank you for the help! I credited you in the code for your work! and I fixed a couple typos! =D

local textLabel = script.Parent
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char.Humanoid
local hrp = char.HumanoidRootPart

local isOnTheMove = false

hum.StateChanged:Connect(function(_, currentState)
	if currentState == Enum.HumanoidStateType.Running then
		isOnTheMove = true
		while isOnTheMove do
			local pos = char.HumanoidRootPart.Position
			local xPos = math.round(pos.X)
			local yPos = math.round(pos.Y)
			local zPos = math.round(pos.Z)
			textLabel.Text = string.format("%d, %d, %d", xPos, yPos, zPos)
			task.wait(1/33.333)
		end
	elseif currentState == Enum.HumanoidStateType.None then
		isOnTheMove = false
	end
end)
--Credits to TheeDeathCaster on the devforum for this code!

Awesome sauce. It’ll probably still need some tinkering with a new edit, but it should get the job done. Hopefully the wait interval isn’t too long either. =p