|
| 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 |
|
|
|
| 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 |
|
|
| |
|
|
| 31 Dec 2015 10:35 AM |
function getPlayerFromCharacter(character) return game.Players:FindFirstChild(character.Name) end |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
| |
|
|
| 31 Dec 2015 10:41 AM |
Seriously just try my function.
getPlayerFromCharacter(game.Workspace:FindFirstChild("BFFstick00")) -- Just an example |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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 |
|
|
|
| 31 Dec 2015 10:44 AM |
| Bens script is currently working... |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| Joined: 31 Dec 2009 |
| Total Posts: 681 |
|
|
| 31 Dec 2015 10:48 AM |
Try making an NPC touch the brick.
|
|
|
| Report Abuse |
|
|
|
| 31 Dec 2015 10:48 AM |
| So your telling me NPCs can be accessed through the Players Section? |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 31 Dec 2015 10:57 AM |
| If you used my function NPCs would return nil. |
|
|
| Report Abuse |
|
|
| |
|