Text not changing to torso coordinate value

This is very simple, beware.

Ok, I made some code, its probably awfully formatted or whatever but I’m really just trying to get this script working because its literally just the text changing to the coordinates of the players torso.
There are no errors but it just doesn’t work. In fact, for the longest time I’ve NEVER been able to script text even if I do everything the way I think you need to do it.

I apologize if this is a very little fix, but I’m confused and would like some help on this. Keep in mind that I’m very new to scripting so this could really all be me doing this the wrong way.

script.Parent.Text = game.Players.LocalPlayer.Character.Torso.Position.Y
wait(0.01)

Thanks!

for some reason Position never really works with a Character, so use CFrame instead like this:

script.Parent.Text = game.Players.LocalPlayer.Character.Torso.CFrame.Position.Y
wait(0.01)
1 Like

Ok, so I changed that. It still seems to not change the text at all. Do you know why this might be happening?
And there’s no errors.

Btw, I’m sorry I was gonna post a different post but it was drafted and I forgot to change the title, oops!

You should probably wait for the character to actually spawn like this then:

game.Players.LocalPlayer.CharacterAdded:Wait()
script.Parent.Text = game.Players.LocalPlayer.Character:WaitForChild("Torso").CFrame.Position.Y
wait(0.01)

Assuming you didn’t already do that.

1 Like

I didn’t add that because I’m a newbie at scripting lol. Anyway, I wrote that down, but I was left with the same outcome.

Reference the Player’s Character as this:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

That way, it will check if there’s a valid Character Model already in store (Player.Character) or will wait until a Character gets added (Player.CharacterAdded:Wait())

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local Torso = Character:WaitForChild("Torso")

script.Parent.Text = Torso.Position.Y
wait(0.01)
1 Like

Thanks! I for sure thought it was the text assigning but I guess it was the position. One more thing, is there a way to only display the whole number, and not the decimals?

You could just round the number using math.round()

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local Torso = Character:WaitForChild("Torso")
local RoundedPosition = math.round(Torso.Position.Y)

script.Parent.Text = RoundedPosition
wait(0.01)

This would return the closest whole number depending on what Torso.Position.Y is defined as

1 Like

So now, the only problem is that the value doesn’t update, and it just sticks with the coordinate I started at. I didn’t say I wanted it to constantly update it and I should have, sorry.

I also apologize for my pickiness!

Ah that’s fine

What we could do, is either get a GetPropertyChangedSignal frequently checking for the Torso’s Position changing, or we can loop this using a RunService loop

RenderStepped would be a good example on how we could implement this, as it’s capable of running way f a s t e r than a simple wait()

Try this:

local RunService = game:GetService("RunService")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local Torso = Character:WaitForChild("Torso")

RunService.RenderStepped:Connect(function()
    local RoundedPosition = math.round(Torso.Position.Y)
    script.Parent.Text = RoundedPosition
end)
1 Like