generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Get A Player's Position

Previous Thread :: Next Thread 
TAWonderz1994 is not online. TAWonderz1994
Joined: 30 Jun 2016
Total Posts: 46
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
unwarranted is not online. unwarranted
Joined: 05 Jun 2009
Total Posts: 1087
04 Jul 2016 10:52 PM
print(player.Character.Torso.Position)


mom wheres the spaghetti | R$18,851
Report Abuse
TAWonderz1994 is not online. TAWonderz1994
Joined: 30 Jun 2016
Total Posts: 46
04 Jul 2016 10:53 PM
Thanks
Report Abuse
TAWonderz1994 is not online. TAWonderz1994
Joined: 30 Jun 2016
Total Posts: 46
04 Jul 2016 10:54 PM
global var player doesn't exist.
Report Abuse
unwarranted is not online. unwarranted
Joined: 05 Jun 2009
Total Posts: 1087
04 Jul 2016 10:56 PM
you need to define player yourself


mom wheres the spaghetti | R$18,851
Report Abuse
TAWonderz1994 is not online. TAWonderz1994
Joined: 30 Jun 2016
Total Posts: 46
04 Jul 2016 10:56 PM
Oh
Report Abuse
TAWonderz1994 is not online. TAWonderz1994
Joined: 30 Jun 2016
Total Posts: 46
04 Jul 2016 10:59 PM
Sorry, but how do I define player?
Report Abuse
DiamondBladee is not online. DiamondBladee
Joined: 24 Feb 2013
Total Posts: 3527
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
TAWonderz1994 is not online. TAWonderz1994
Joined: 30 Jun 2016
Total Posts: 46
04 Jul 2016 11:02 PM
My Script Is in StarterGUI.
Report Abuse
unwarranted is not online. unwarranted
Joined: 05 Jun 2009
Total Posts: 1087
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
TAWonderz1994 is not online. TAWonderz1994
Joined: 30 Jun 2016
Total Posts: 46
04 Jul 2016 11:03 PM
Im not new to Lua, just Roblox Lua, thanks for the links :)
Report Abuse
TAWonderz1994 is not online. TAWonderz1994
Joined: 30 Jun 2016
Total Posts: 46
04 Jul 2016 11:16 PM
The script is in StarterGUI, not sure if that is server or client.
Report Abuse
DiamondBladee is not online. DiamondBladee
Joined: 24 Feb 2013
Total Posts: 3527
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
nicemike40 is not online. nicemike40
Joined: 19 Dec 2008
Total Posts: 1814
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 is not online. 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
nicemike40 is not online. nicemike40
Joined: 19 Dec 2008
Total Posts: 1814
04 Jul 2016 11:54 PM
True. I was lazy. I apologize.


Report Abuse
RecurringNightmare is not online. RecurringNightmare
Joined: 05 Jul 2012
Total Posts: 15336
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
Justin_Trill is not online. Justin_Trill
Joined: 28 Aug 2014
Total Posts: 636
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
DiamondBladee is not online. DiamondBladee
Joined: 24 Feb 2013
Total Posts: 3527
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
Justin_Trill is not online. Justin_Trill
Joined: 28 Aug 2014
Total Posts: 636
05 Jul 2016 09:05 PM
@DiamondBladee

Touché. but in this case its not so I win.


Report Abuse
Studio_FPS is not online. Studio_FPS
Joined: 05 Jun 2016
Total Posts: 53
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image