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.
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)
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
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.
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)