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 » Scripters
Home Search
 

Re: Player a nil value?

Previous Thread :: Next Thread 
Burglered is not online. Burglered
Joined: 14 Jul 2011
Total Posts: 962
17 Jan 2016 01:58 PM
I need help my script. I am trying to make it where when you touch a brick, a gui shows up, but an error shows up saying 'attempt to find index 'player'(a nil value).
Here is my code:

script.Parent.Touched:connect(function(hit)
local db = false
if db == false then
db = true
local player = game.Players:GetPlayerFromCharacter(hit)
local gui = player.PlayerGui.GunGui
gui.Frame.Visible = true
end
end)


siggy.Parent=Player.Signature
Report Abuse
ColonySimulator is not online. ColonySimulator
Joined: 05 Jul 2015
Total Posts: 1721
17 Jan 2016 02:00 PM
script.PArent.Touched:connect(function(hit)
if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
local player = hit.Parent:FindFirstChild("Humanoid")
local db = false
if db == false then
db = true
local gui = player.PlayerGui.GunGui
gui.Frame.Visible = true
end
end
end)
Report Abuse
wonderful72pike is not online. wonderful72pike
Joined: 13 Jul 2010
Total Posts: 7009
17 Jan 2016 02:00 PM
If the player's left leg hits the brick, you're trying to get the player from their left leg which won't find anything. GetPlayerFromCharacter is meant to get it from the character model, not one of the parts. So change that line to this:

local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- .Parent

Another problem: unless you are 100% sure a player is hitting it EVERY SINGLE TIME your script can run into these problems:

- If a bullet hits it and immediately gets destroyed, "hit" can be nil
- Same thing with hit.Parent
- If it's a random brick or enemy then GetPlayerFromCharacter will still return nil
Report Abuse
Burglered is not online. Burglered
Joined: 14 Jul 2011
Total Posts: 962
17 Jan 2016 02:02 PM
Omg I am stupid. I forgot hit.Parent qq.

Thanks for the detailed explanation!
Btw, how would I make it where if you shoot a bullet at a zombie and when it dies, it gives you points?


siggy.Parent=Player.Signature
Report Abuse
WoolHat is not online. WoolHat
Joined: 19 May 2013
Total Posts: 1873
17 Jan 2016 02:03 PM
"hit" is the part that came into contact with the event's block. And you should check to make sure that "hit" is a character's body part.

script.Parent.Touched:connect(function(hit)
local db = false
if db == false then
db = true
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local gui = player.PlayerGui.GunGui
gui.Frame.Visible = true
end
end
end
Report Abuse
WoolHat is not online. WoolHat
Joined: 19 May 2013
Total Posts: 1873
17 Jan 2016 02:04 PM
Also you may want to look at your debounce
Report Abuse
xlaser23 is not online. xlaser23
Joined: 10 Dec 2011
Total Posts: 20341
17 Jan 2016 02:04 PM
getting player from player

Legit



http://www.roblox.com/xla-item?id=290739801http://www.roblox.com/aser-item?id=290739819http://www.roblox.com/23-item?id=290739831 R$206 Tx367 (づ ゚ ³ ゚)づ
Report Abuse
Burglered is not online. Burglered
Joined: 14 Jul 2011
Total Posts: 962
17 Jan 2016 02:05 PM
@above x2

Alright, Ill check for Humanoid to be safe :P


siggy.Parent=Player.Signature
Report Abuse
xNitrospeedx is not online. xNitrospeedx
Joined: 05 Sep 2011
Total Posts: 189
17 Jan 2016 02:06 PM
Well, when the bullet comes into contact with the zombie, subtract the a value from the health of the player and make a check. If the health of the player is 0 or less after the subtraction, add points.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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