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: Getting the player from a hit block?

Previous Thread :: Next Thread 
Solotaire is not online. Solotaire
Joined: 30 Jul 2009
Total Posts: 30356
03 Jul 2012 02:50 AM
This is something I've done plenty of times before, but all of a sudden I can't seem to make it work.

Related Code:


script.Parent.Touched:connect(function(hit)
player = game.Players:getPlayerFromCharacter(hit.Parent)
if game:GetService('BadgeService'):UserHasBadge(player.userId, shirtID) then
end
end)

Is hit.Parent the wrong way to get the character?
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
03 Jul 2012 02:52 AM
script.Parent.Touched:connect(function(hit)
player = game.Players:GetPlayerFromCharacter(hit.Parent)
if game:GetService('BadgeService'):UserHasBadge(player.userId, shirtID) then --Where's shirtID defined?
end
end)
Report Abuse
dddylan98 is not online. dddylan98
Joined: 16 Jul 2008
Total Posts: 1497
03 Jul 2012 02:52 AM
Why not use :findFirstChild(hit.Parent) instead of :getPlayerFromCharacter
Report Abuse
Sehnsucht is not online. Sehnsucht
Joined: 10 Apr 2011
Total Posts: 990
03 Jul 2012 02:52 AM
I would add a check to make sure 'hit.Parent' isn't anything else that may touch the part, causing the script to break.
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
03 Jul 2012 02:53 AM
Because it's normal using :GetPlayerFromCharacter().
Report Abuse
wazup07 is not online. wazup07
Joined: 17 Oct 2009
Total Posts: 313
03 Jul 2012 02:55 AM
Capitalize Get. GetPlayerFromCharacter() that should work.
Report Abuse
wazup07 is not online. wazup07
Joined: 17 Oct 2009
Total Posts: 313
03 Jul 2012 02:56 AM
guess i was a little late.... -_-
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
03 Jul 2012 02:56 AM
I already did that in my correction.
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
03 Jul 2012 02:56 AM
Maybe...

ALL HAIL THE FLOODCHECK!
Report Abuse
Solotaire is not online. Solotaire
Joined: 30 Jul 2009
Total Posts: 30356
03 Jul 2012 02:57 AM
Oh, shirtID was defined as the first line. The output error was "attempting to index global player (a nil value).

Also, I need to check the asset of a player, so I need to get the player, not the humanoid (why are you suggesting findFirstChild? Am i missing something?)
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
03 Jul 2012 02:59 AM
About ShirtID, that's what I wrote in my correction.

About the asset of the player, I don't think a model with a humanoid inside will ever touch your brick there, that's why people mostly check for a humanoid.

About :findFirstChild() (guess what? :FindFirstChild() works aswell), just forget that.
Report Abuse
Solotaire is not online. Solotaire
Joined: 30 Jul 2009
Total Posts: 30356
03 Jul 2012 03:02 AM
"About ShirtID, that's what I wrote in my correction."
That is why I addressed it.

"About the asset of the player, I don't think a model with a humanoid inside will ever touch your brick there, that's why people mostly check for a humanoid."
Not sure what you are trying to explain there, but thank you for the help.

"About :findFirstChild() (guess what? :FindFirstChild() works aswell), just forget that."
I prefer the lower case, but I'll probably use it with capital letters from now on.
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
03 Jul 2012 03:05 AM
It doesn't matter. :findFirstChild() is for old users.
Report Abuse
Solotaire is not online. Solotaire
Joined: 30 Jul 2009
Total Posts: 30356
03 Jul 2012 03:08 AM
Now the script only works once. I'm confused. xD
Report Abuse
Solotaire is not online. Solotaire
Joined: 30 Jul 2009
Total Posts: 30356
03 Jul 2012 03:11 AM
Nevermind it was breaking because non-players were touching it and i forgot to check that
Report Abuse
Kelvin98 is not online. Kelvin98
Joined: 14 Dec 2008
Total Posts: 272
03 Jul 2012 04:40 AM
script.Parent.Touched:connect(function(hit)
if hit.Parent:findFirstChild("Humanoid") ~= nil then
player = game.Players:getPlayerFromCharacter(hit.Parent)
if game:GetService('BadgeService'):UserHasBadge(player.userId, shirtID) then
end
end
end)
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