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 » Scripting Helpers
Home Search
 

Re: GetPlayerFromCharacter(character) function

Previous Thread :: Next Thread 
3027474 is not online. 3027474
Joined: 30 Dec 2008
Total Posts: 1636
24 Jun 2012 05:47 PM
How does work and can I change 'character'(if so please tell me what I would replace it with)
Report Abuse
ElectricAxel is not online. ElectricAxel
Joined: 15 May 2009
Total Posts: 16239
24 Jun 2012 05:52 PM
Its a Method of the Service Players (game.Players), it takes 1 argument (unsure if more?), and the argument should be the "Character" of the player, usually the model with the same name as the player located in the Workspace service. xP

game.Players:GetPlayerFromCharacter(workspace.ElectricAxel) --should return game.Players.ElectricAxel
Report Abuse
3027474 is not online. 3027474
Joined: 30 Dec 2008
Total Posts: 1636
24 Jun 2012 05:56 PM
Then whats the point of that? You could just say game.Players.EletricAxel
Report Abuse
ElectricAxel is not online. ElectricAxel
Joined: 15 May 2009
Total Posts: 16239
24 Jun 2012 05:58 PM
When a player touches a brick and you want to get the player, say the Leg, Leg is inside my Character, so you could do:

script.Parent.Touched:connect(function(hit)
local player = game.Players:getPlayerFromCharacter(hit.Parent)
if player then
print(player.Name.. " has touched the objective!")
end
end)
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
24 Jun 2012 06:07 PM
Oh if you really wanted, it could take two arguments.

script.Parent.Touched:connect(function(hit)
local player = game.Players.GetPlayerFromCharacter(Game.Players, hit.Parent)
if player then
print(player.Name.. " has touched the objective!")
end
end)
Report Abuse
adark is not online. adark
Joined: 13 Jan 2008
Total Posts: 6412
24 Jun 2012 06:08 PM
What does that first argument, Game.Players, actually mean?

I assume it can be changed to something else?
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
24 Jun 2012 06:10 PM
When you index the function (.) instead of methodize it (:) then you remove the default given argument. All methods use their calling factor (the thing before the colon) as the first argument.
Report Abuse
adark is not online. adark
Joined: 13 Jan 2008
Total Posts: 6412
24 Jun 2012 06:12 PM
I learnded something new todai! Thankee, Mr. NicNac.
Report Abuse
ElectricAxel is not online. ElectricAxel
Joined: 15 May 2009
Total Posts: 16239
24 Jun 2012 06:15 PM
Oh, hai MNN... Uhm always with the outstanding clothes I see... And yes, I guess I did forget about that trick to add 1 unneeded argument. :P
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
24 Jun 2012 06:16 PM
Technically I'm not wearing anything but a hat. But ROBLOX doesn't know that.

"1 unneeded argument"

Definitely useless.
Report Abuse
ElectricAxel is not online. ElectricAxel
Joined: 15 May 2009
Total Posts: 16239
24 Jun 2012 06:17 PM
lol You could say you are wearing a costume.

You know what I meant, of course it is important, but why not use it as a method instead of a function?
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
24 Jun 2012 06:19 PM
Oh no, I meant literally creating the argument in the raw code. It is useless to not call it as a method.
Report Abuse
ElectricAxel is not online. ElectricAxel
Joined: 15 May 2009
Total Posts: 16239
24 Jun 2012 06:21 PM
What happens if I use the connect from one event as a function and specify another event instead? O-o
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
24 Jun 2012 06:22 PM
Than it should do the other event. Like this,

part.Touched.connect(Game.Players.PlayerAdded, function(p)
print(p.Name)
end)
Report Abuse
adark is not online. adark
Joined: 13 Jan 2008
Total Posts: 6412
24 Jun 2012 06:25 PM
Would that start looking for Players added after the brick is touched, or right off the bat?
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
24 Jun 2012 06:26 PM
The Touched event doesn't even connect.
Report Abuse
adark is not online. adark
Joined: 13 Jan 2008
Total Posts: 6412
24 Jun 2012 06:29 PM
Oh, derp, didn't read it right.
So you could just use
connect(event, function)
on its own?
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
24 Jun 2012 06:31 PM
No. It's like the workspace. A part is in the workspace.

Workspace.Part

To get anything inside that part you have to do

Workspace.Part.Something

The function 'connect' is inside events. I have to use a random event to get that function.
Report Abuse
adark is not online. adark
Joined: 13 Jan 2008
Total Posts: 6412
24 Jun 2012 06:34 PM
Okay.

Wellp, I learnded something *completely* todai. :D
Report Abuse
ElectricAxel is not online. ElectricAxel
Joined: 15 May 2009
Total Posts: 16239
24 Jun 2012 06:38 PM
Interesting, thanks. So the connect function is the same for every event.
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
24 Jun 2012 06:39 PM
Hopefully, or else I just messed up your grip of the function.
Report Abuse
adark is not online. adark
Joined: 13 Jan 2008
Total Posts: 6412
24 Jun 2012 06:40 PM
MrNicNac, I just have a mind full of [BLEEP] all of the times. Most anything you can say will just shift some stuff around.
Report Abuse
ElectricAxel is not online. ElectricAxel
Joined: 15 May 2009
Total Posts: 16239
24 Jun 2012 06:40 PM
What do you mean hopefully? Aren't you sure of this? xD
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
24 Jun 2012 06:41 PM
Well it "should" work. I don't know. I can't try it.
Report Abuse
ElectricAxel is not online. ElectricAxel
Joined: 15 May 2009
Total Posts: 16239
24 Jun 2012 06:54 PM
Oh, I see... I'll test it some day. xP
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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