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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|