Contrary
|
  |
| Joined: 08 Jan 2011 |
| Total Posts: 1306 |
|
|
| 05 Sep 2015 03:53 PM |
Hello, I'm trying to make script that prints the (X,Y,Z) position of the LocalPlayer whenever they move. I tried making a function, but I know it isn't correct. How do I make this work?
player = player = game.Players.LocalPlayer
player.Changed:connect(function() local plrPos = player.Character.Torso.Position print (plrPos) end) |
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 05 Sep 2015 03:55 PM |
print(tostring(plrPos)
maybe? |
|
|
| Report Abuse |
|
|
|
| 05 Sep 2015 03:56 PM |
local player = game.Players.LocalPlayer; local char = player.Character or player.CharacterAdded:wait(); local torso = char:WaitForChild("Torso")
torso.Changed:connect(function() print(torso.Position) end) |
|
|
| Report Abuse |
|
|
Contrary
|
  |
| Joined: 08 Jan 2011 |
| Total Posts: 1306 |
|
|
| 05 Sep 2015 03:56 PM |
Well, what I'm curious about is how the function knows what property it's look for to be changed.
Like, there are tons of properties that are being changed on the character when it moves... not just position. |
|
|
| Report Abuse |
|
|
|
| 05 Sep 2015 03:58 PM |
local player = game.Players.LocalPlayer; local char = player.Character or player.CharacterAdded:wait(); local torso = char:WaitForChild("Torso")
torso.Changed:connect(function(property) if property == "Position" then print(torso.Position) end end)
|
|
|
| Report Abuse |
|
|
Contrary
|
  |
| Joined: 08 Jan 2011 |
| Total Posts: 1306 |
|
| |
|
Contrary
|
  |
| Joined: 08 Jan 2011 |
| Total Posts: 1306 |
|
|
| 05 Sep 2015 04:09 PM |
| Hmm... it oddly only seems to print it once, which is right when I spawn. It doesn't seem to print it every time I move. |
|
|
| Report Abuse |
|
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
|
| 05 Sep 2015 04:11 PM |
| Properties that are Vector3s, CFrames, etc do not trigger the Changed event on change |
|
|
| Report Abuse |
|
|
Contrary
|
  |
| Joined: 08 Jan 2011 |
| Total Posts: 1306 |
|
|
| 05 Sep 2015 04:11 PM |
| Do you what properties do? I could use one of those properties that trigger it, then just have it print the position. |
|
|
| Report Abuse |
|
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
|
| 05 Sep 2015 04:13 PM |
| I'm pretty sure that all basic Lua datatypes fire the Changed event upon changed (e.g numbers, strings). Honestly, I would just use a loop, ik people don't approve of loops like this but whatever |
|
|
| Report Abuse |
|
|
chimmmihc
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 2420 |
|
|
| 05 Sep 2015 04:13 PM |
| I think this guy is a time traveller, he types like he's in the late 1600's |
|
|
| Report Abuse |
|
|
|
| 05 Sep 2015 04:14 PM |
I don't know then lol
This code is NOT ideal if you're printing because it'll print every 1/60 of a second, but if you want to update a GUI with your cords, it's great.
local player = game.Players.LocalPlayer; local char = player.Character or player.CharacterAdded:wait(); local torso = char:WaitForChild("Torso")
game:GetService("RunService").RenderStepped:connect(function() print(torso.Position) end) |
|
|
| Report Abuse |
|
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
|
| 05 Sep 2015 04:15 PM |
Also, @Wowgnomes
the print function already uses tostring() on the arguments so it is not necessary |
|
|
| Report Abuse |
|
|
Contrary
|
  |
| Joined: 08 Jan 2011 |
| Total Posts: 1306 |
|
|
| 05 Sep 2015 04:15 PM |
| What? Who's typing like they are from the late 1600's? |
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 05 Sep 2015 04:35 PM |
| it's not necessary but is it wrong |
|
|
| Report Abuse |
|
|
| |
|