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: Can GetPlayerFromCharacter be used in a LocalScript?

Previous Thread :: Next Thread 
Zkiller11 is not online. Zkiller11
Joined: 25 Aug 2009
Total Posts: 2914
21 Jun 2013 07:58 PM
It doesn't seem to be working for me..
Report Abuse
PerpetualMovement is not online. PerpetualMovement
Joined: 04 Dec 2012
Total Posts: 1001
21 Jun 2013 08:00 PM
Yes but you don't really need it. Just use
game.Players.LocalPlayer
Report Abuse
Geomaster is not online. Geomaster
Joined: 05 Jul 2008
Total Posts: 1480
21 Jun 2013 08:00 PM
Assuming you're using a LocalScript (which can only run in backpacks or players anyways), you can just do:

player = game.Players.LocalPlayer -- Simple as that, only works in LocalScripts
char = player.Character
Report Abuse
Zkiller11 is not online. Zkiller11
Joined: 25 Aug 2009
Total Posts: 2914
21 Jun 2013 08:13 PM
I don't think LocalPlayer will work for what I'm using it for.
Report Abuse
PerpetualMovement is not online. PerpetualMovement
Joined: 04 Dec 2012
Total Posts: 1001
21 Jun 2013 08:14 PM
Well if the LocalScript isn't inside the Player then there is no point in using it.
Report Abuse
swmaniac is not online. swmaniac
Joined: 28 Jun 2008
Total Posts: 15773
21 Jun 2013 08:21 PM
@perpetual

If you code a weapon that needs to get to the target's Player, then you need GetPlayerFromCharacter.


To the OP, yes it works in a localscript.
Report Abuse
Zkiller11 is not online. Zkiller11
Joined: 25 Aug 2009
Total Posts: 2914
21 Jun 2013 08:23 PM
@Swmaniac:

Yes, that's what I'm trying to do. The only issue is, my anti-teamkill function isn't working. Can I use GetPlayerFromCharacter for this method? The output really isn't telling me anything useful.
Report Abuse
btft is not online. btft
Joined: 19 Feb 2011
Total Posts: 1512
21 Jun 2013 08:30 PM
make sure you are using game:service'Players':GetPlayerFromCharacter()
Report Abuse
Zkiller11 is not online. Zkiller11
Joined: 25 Aug 2009
Total Posts: 2914
21 Jun 2013 08:32 PM
@btft:

What? I didn't have to use that when I used GetPlayerFromCharacter before..
Report Abuse
btft is not online. btft
Joined: 19 Feb 2011
Total Posts: 1512
21 Jun 2013 08:33 PM
I mean. make sure you are using game.Players:GetPlayerFromCharacter().

meaning game.Players.
Report Abuse
Zkiller11 is not online. Zkiller11
Joined: 25 Aug 2009
Total Posts: 2914
21 Jun 2013 08:50 PM
This is what I have:

b.Touched:connect(function(hit)
if hit then
if hit.Parent:findFirstChild("Humanoid") then
if hit.Parent ~= script.Parent.Parent.Parent then
character = hit.Parent
player = game.Players:GetPlayerFromCharacter(character)
if player.TeamColor ~= script.Parent.Parent.Parent.TeamColor then
local human = hit.Parent:findFirstChild("Humanoid")
human.Health = human.Health - math.random(10, 15)
end
end
end
end
end)
end
script.Parent.Parent.Equipped:connect(function(m) m.Button1Down:connect(onButton1Down)
end)

This works up until I put the TeamColor part in. For some reason that breaks the entire script. What am I doing wrong here? This is a LocalScript inside a Part, Inside a Tool, inside a Player's Backpack.
Report Abuse
btft is not online. btft
Joined: 19 Feb 2011
Total Posts: 1512
21 Jun 2013 08:53 PM
Make sure script.Parent.Parent.Parent.TeamColor is a BrickColor Value.
and,

script.Parent.Parent.Parent.TeamColor is what?
Report Abuse
Zkiller11 is not online. Zkiller11
Joined: 25 Aug 2009
Total Posts: 2914
21 Jun 2013 08:55 PM
script.Parent.Parent.Parent.Parent.TeamColor is the Character's TeamColor that is holding the tool. And yes, it should be a BrickColor Value, as long as TeamColors are BrickColor Values.
Report Abuse
PerpetualMovement is not online. PerpetualMovement
Joined: 04 Dec 2012
Total Posts: 1001
21 Jun 2013 08:56 PM
No it's not because when the player is holding the tool it goes into the Character. It's no longer in the backpack so that wouldn't work.
Report Abuse
Zkiller11 is not online. Zkiller11
Joined: 25 Aug 2009
Total Posts: 2914
21 Jun 2013 08:58 PM
@Perpetual:

I accounted for that.
Report Abuse
btft is not online. btft
Joined: 19 Feb 2011
Total Posts: 1512
21 Jun 2013 08:59 PM
Characters don't have a teamcolor Value.
Report Abuse
Zkiller11 is not online. Zkiller11
Joined: 25 Aug 2009
Total Posts: 2914
21 Jun 2013 09:05 PM
@Btft:

Derp I meant Player. This:

http://wiki.roblox.com/index.php/RBX.lua.Player_(Object)
Report Abuse
btft is not online. btft
Joined: 19 Feb 2011
Total Posts: 1512
21 Jun 2013 09:07 PM
if player.TeamColor ~= game.Players.LocalPlayer.TeamColor then
??
Report Abuse
Zkiller11 is not online. Zkiller11
Joined: 25 Aug 2009
Total Posts: 2914
22 Jun 2013 09:02 PM
@Btft:

That fixed it!! Thanks!! I had been working on that, trying to figure it out for quite a while, it really had me confused. Thanks again all!
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