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() help [SIMPLE SCRIPT]

Previous Thread :: Next Thread 
3xpert is not online. 3xpert
Joined: 11 May 2013
Total Posts: 1513
16 Jul 2013 02:13 PM
function onTouched(hit)
chr = hit.Parent:GetPlayerFromCharacter()
if chr.TeamColor == BrickColor.new("Bright red") and chr.Character.Humanoid.Health ~= 0 then
script.Parent.BrickColor = BrickColor.new("Bright red")
end
end
script.Parent.Touched:connect(onTouched)

It's not working, and I'm pretty sure that it's because I'm using the :GetPlayerFromCharacter() function wrong.
Can someone help?

NOTE : Normal script inside of regular part.
Report Abuse
RoyStanford is not online. RoyStanford
Joined: 21 Oct 2008
Total Posts: 2222
16 Jul 2013 02:14 PM
Try

chr = game.Players[hit.Parent.Name]
if not char then return end
Report Abuse
Xtreme101 is not online. Xtreme101
Joined: 03 Jan 2009
Total Posts: 4385
16 Jul 2013 02:16 PM
Roy...

chr = game.Players[hit.Parent.Name]
if not chr then return end
Report Abuse
RoyStanford is not online. RoyStanford
Joined: 21 Oct 2008
Total Posts: 2222
16 Jul 2013 02:18 PM
I'm so used to writing it as char, not chr, my bad
Report Abuse
3xpert is not online. 3xpert
Joined: 11 May 2013
Total Posts: 1513
16 Jul 2013 02:18 PM
Where do I place the if not chr then return end?

Thanks for the help guys... :)
Report Abuse
RoyStanford is not online. RoyStanford
Joined: 21 Oct 2008
Total Posts: 2222
16 Jul 2013 02:19 PM
right after you declare chr
Report Abuse
canada1232111 is not online. canada1232111
Joined: 16 Jan 2013
Total Posts: 863
16 Jul 2013 02:20 PM
3xpert

switch it with this part:

chr = hit.Parent:GetPlayerFromCharacter()
Report Abuse
canada1232111 is not online. canada1232111
Joined: 16 Jan 2013
Total Posts: 863
16 Jul 2013 02:21 PM
OH wait nvm nvm nvm DUN STOP STOOPP Dun do wut I said. kthx


[[FLOOODCHECKK]]
Report Abuse
grimm343 is not online. grimm343
Joined: 18 Sep 2008
Total Posts: 2796
16 Jul 2013 02:23 PM
function onTouched(hit)
chr = game.Players:GetPlayerFromCharacter(hit.Parent)
if chr and chr.TeamColor == BrickColor.new("Bright red") and chr.Character.Humanoid.Health ~= 0 then
script.Parent.BrickColor = BrickColor.new("Bright red")
end
end
script.Parent.Touched:connect(onTouched)


You didn't properly use GetPlayerFromCharacter, and you didn't check to see if 'chr' existed. GetPlayerFromCharacter returns the Player or nil.
Report Abuse
3xpert is not online. 3xpert
Joined: 11 May 2013
Total Posts: 1513
16 Jul 2013 02:29 PM
Thank you Grimm!
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