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: Accessing Player through its character in workspace

Previous Thread :: Next Thread 
RaulChaser is not online. RaulChaser
Joined: 07 Dec 2014
Total Posts: 655
31 Dec 2015 10:22 AM
How would I get the player in workspace to get its other self... Does that make sense?

Anyways... I'm doing an onTouched script that accesses your leaderstats. Ive seen many popular games doing that but I couldn't figure out how to do that. I don't wanna use localplayer because my output returns nil when I test it in a server.
Report Abuse
AnonyAnonymous is not online. AnonyAnonymous
Joined: 23 Jun 2013
Total Posts: 6332
31 Dec 2015 10:25 AM
You could simply retrieve the name of the character and search the Players table for the individual.

"game.Players:FindFirstChild(Character.Name)", for example, would attempt to locate an object within the list of players with the character's name.
Report Abuse
RaulChaser is not online. RaulChaser
Joined: 07 Dec 2014
Total Posts: 655
31 Dec 2015 10:29 AM
I don't get it...
Report Abuse
BFFstick00 is not online. BFFstick00
Joined: 25 Oct 2010
Total Posts: 800
31 Dec 2015 10:35 AM
function getPlayerFromCharacter(character)
return game.Players:FindFirstChild(character.Name)
end
Report Abuse
litalela is not online. litalela
Joined: 30 Mar 2010
Total Posts: 6267
31 Dec 2015 10:36 AM
jesus christ some people on this forum make me angry

http://wiki.roblox.com/index.php?title=API:Class/Players/GetPlayerFromCharacter

dont use these people's silly ways to do it

➳Lɪᴛᴀʟᴇʟᴀ ɪs ᴍʏ ɴᴀᴍᴇ, Lᴜᴀ ɪs ᴍʏ ɢᴀᴍᴇツ
Report Abuse
RaulChaser is not online. RaulChaser
Joined: 07 Dec 2014
Total Posts: 655
31 Dec 2015 10:38 AM
I tried that already... :/
But the output says it couldn't find it, that's why I made this Post
Report Abuse
litalela is not online. litalela
Joined: 30 Mar 2010
Total Posts: 6267
31 Dec 2015 10:39 AM
part.Touched:connect(function(hit)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if player then
-- your code here
end
end)

➳Lɪᴛᴀʟᴇʟᴀ ɪs ᴍʏ ɴᴀᴍᴇ, Lᴜᴀ ɪs ᴍʏ ɢᴀᴍᴇツ
Report Abuse
TheBenSquare is not online. TheBenSquare
Joined: 13 Dec 2009
Total Posts: 13604
31 Dec 2015 10:40 AM
script.Parent.Touched:connect(function(hit)
if hit.Parent:findFirstChild("Humanoid") then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 5
end
end)
Report Abuse
RaulChaser is not online. RaulChaser
Joined: 07 Dec 2014
Total Posts: 655
31 Dec 2015 10:41 AM
mkay, thank you!
Report Abuse
BFFstick00 is not online. BFFstick00
Joined: 25 Oct 2010
Total Posts: 800
31 Dec 2015 10:41 AM
Seriously just try my function.

getPlayerFromCharacter(game.Workspace:FindFirstChild("BFFstick00")) -- Just an example
Report Abuse
litalela is not online. litalela
Joined: 30 Mar 2010
Total Posts: 6267
31 Dec 2015 10:42 AM
ben, dont be silly

they could be NPC and that would error out

➳Lɪᴛᴀʟᴇʟᴀ ɪs ᴍʏ ɴᴀᴍᴇ, Lᴜᴀ ɪs ᴍʏ ɢᴀᴍᴇツ
Report Abuse
AnonyAnonymous is not online. AnonyAnonymous
Joined: 23 Jun 2013
Total Posts: 6332
31 Dec 2015 10:44 AM
"I don't get it..."

Roblox has a hierarchical-system of "tables", which are merely sets of specified data.

"Workspace" and "Players" are examples of tables within the Roblox scripting-environment that cannot be directly modified by the user.

"Child" refers to any element within the set of data.

"FindFirstChild" is a default function that will search a given table by attempting to obtain a single member of the set of data that has the name specified within the parentheses.

".Name" merely returns the name of the "child" in the form of string data.


"game.Workspace:FindFirstChild(Child.Name)" would retrieve the object within the Workspace table by obtaining the name of the object that the variable "Child" refers to and instructing the function to search for any objects with that particular name.
Report Abuse
RaulChaser is not online. RaulChaser
Joined: 07 Dec 2014
Total Posts: 655
31 Dec 2015 10:44 AM
Bens script is currently working...
Report Abuse
BFFstick00 is not online. BFFstick00
Joined: 25 Oct 2010
Total Posts: 800
31 Dec 2015 10:47 AM
He's been helped already, just try not to check NPCs for their player entity and you will be fine.
Report Abuse
kert109 is not online. kert109
Joined: 31 Dec 2009
Total Posts: 681
31 Dec 2015 10:48 AM
Try making an NPC touch the brick.


Report Abuse
RaulChaser is not online. RaulChaser
Joined: 07 Dec 2014
Total Posts: 655
31 Dec 2015 10:48 AM
So your telling me NPCs can be accessed through the Players Section?
Report Abuse
RaulChaser is not online. RaulChaser
Joined: 07 Dec 2014
Total Posts: 655
31 Dec 2015 10:50 AM
+kert109

I'm making a level door, in which it looks for leaderstats-level.
If I'm correct, this script:

game.Players.PlayerAdded:connect(function(plr)

local leaderstats = Instance.new("Model")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr

local Experience = Instance.new("IntValue") --Level
Experience.Name = "Level"
Experience.Value = "0"
Experience.Parent = leaderstats

local Gold = Instance.new("IntValue") --Gold
Gold.Name = "Gold"
Gold.Value = 0
Gold.Parent = leaderstats

end)
----------------------------------
Wouldn't insert this Instance into an NPC
Report Abuse
BFFstick00 is not online. BFFstick00
Joined: 25 Oct 2010
Total Posts: 800
31 Dec 2015 10:57 AM
If you used my function NPCs would return nil.
Report Abuse
RaulChaser is not online. RaulChaser
Joined: 07 Dec 2014
Total Posts: 655
31 Dec 2015 11:02 AM
Mkay!
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