|
| 04 Jul 2016 10:51 PM |
| I know this is very basic, but I can't seem to be able to find out how to get a players position |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 10:52 PM |
print(player.Character.Torso.Position)
mom wheres the spaghetti | R$18,851 |
|
|
| Report Abuse |
|
|
| |
|
|
| 04 Jul 2016 10:54 PM |
| global var player doesn't exist. |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 10:56 PM |
you need to define player yourself
mom wheres the spaghetti | R$18,851 |
|
|
| Report Abuse |
|
|
| |
|
|
| 04 Jul 2016 10:59 PM |
| Sorry, but how do I define player? |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 11:01 PM |
It depends on where your script is! Is it on the server, or the client? If you aren't sure, tell me where it is in the explorer.
"Tell me and I forget. Teach me and I remember. Involve me and I learn." - Benjamin Franklin |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 11:02 PM |
| My Script Is in StarterGUI. |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 11:02 PM |
you seem new to scripting (no offense) so i'd read up on some tutorials,
http://wiki.roblox.com/index.php?title=Intro_to_Scripting http://wiki.roblox.com/index.php?title=AllTutorials
or just check youtube for some, i recommend peaspod or friaza.
mom wheres the spaghetti | R$18,851 |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 11:03 PM |
| Im not new to Lua, just Roblox Lua, thanks for the links :) |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 11:16 PM |
| The script is in StarterGUI, not sure if that is server or client. |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 11:18 PM |
Stuff in startergui gets cloned to:
game.Players[Player_Name].PlayerGui
You'll need to use a LocalScript on the client to access some important variables. Players has a property called LocalPlayer that returns the Player object of the client it was called from.
game.Players.LocalPlayer
From there you can use the Character property and go on to the Torso and get the position :)
"Tell me and I forget. Teach me and I remember. Involve me and I learn." - Benjamin Franklin |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 11:44 PM |
To simplify:
- Put a LocalScript inside StarterGui - In that LocalScript:
local player = game.Players.LocalPlayer;
local playerPosition = player.Character.Torso.Position;
print(playerPosition);
NOTE: This is a dangerous way to do things. For instance, what happens when the torso gets deleted because of an explosion or something? Then saying Character.Torso will give you an error. To fix this, you should read up on FindFirstChild and nil checks.
|
|
|
| Report Abuse |
|
|
Aethex
|
  |
| Joined: 16 Oct 2011 |
| Total Posts: 2193 |
|
|
| 04 Jul 2016 11:51 PM |
@nicemike40 The post would be nicer if it actually worked.
@OP You need to make sure the character exists as well. This can be done by waiting for the CharacterAdded event to complete. Example:
--in a localscript
local plr = game.Players.LocalPlayer; -- assigns the local player to the variable
local char = plr.Character or plr.CharacterAdded:wait(); -- yields until character is added
local torso = char:WaitForChild("Torso"); -- yields until Torso exists
local torsoPosition = torso.Position; -- sets variable to torso's position
print(torsoPosition); -- prints torso's position |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 11:54 PM |
True. I was lazy. I apologize.
|
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 11:58 PM |
https://www.youtube.com/channel/UCXF7DezJJEEm1kGwmSq_ELg
I think my tutorials are a nice learning source as well
|
|
|
| Report Abuse |
|
|
|
| 05 Jul 2016 02:15 AM |
Obviously you're new to coding in ALL. Not JUST ROBLOX Lua, this is obvious due to the fact that you were unable to diagnose your own problem (not defining a variable). That's something that's used in EVERY programming language.
|
|
|
| Report Abuse |
|
|
|
| 05 Jul 2016 01:45 PM |
@Justin It could be argued that Roblox may have player pre-defined on local scripts.
"Tell me and I forget. Teach me and I remember. Involve me and I learn." - Benjamin Franklin |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2016 09:05 PM |
@DiamondBladee
Touché. but in this case its not so I win.
|
|
|
| Report Abuse |
|
|
|
| 05 Jul 2016 09:06 PM |
local script
local player = game.Players.LocalPlayer local char = player.Character local torsopos = char.Torso.Position -- or char.Torso.CFrame
|
|
|
| Report Abuse |
|
|