|
| 15 Mar 2016 02:41 PM |
Here are the lines of code I have been struggling with. I know for a fact the first two work because the print works, but I can't figure out why the last one won't work. I have checked and double checked that all of it's parents and everything are alined right and they are and it still doesn't work. I keep getting the error message in output of Players.Player1.PlayerGui.Leaderboard.Main.Challenge.LocalScript:14: attempt to index local 'target' (a nil value)
Here is my code. local target = game.Workspace.PlayerDueling:FindFirstChild(Challengee)--Finds Challengee print'found target' target.Event1:FireServer() --Launch Event
Any help would be greatly appreciated. |
|
|
| Report Abuse |
|
|
|
| 15 Mar 2016 02:45 PM |
| It's not able to find game.Workspace.PlayerDueling[Challengee] |
|
|
| Report Abuse |
|
|
|
| 15 Mar 2016 02:47 PM |
| But it does because, it gives me the print message in output. |
|
|
| Report Abuse |
|
|
|
| 15 Mar 2016 02:51 PM |
| FindFirstChild will either return the child or nil if not found |
|
|
| Report Abuse |
|
|
Locard
|
  |
| Joined: 13 Apr 2014 |
| Total Posts: 3516 |
|
|
| 15 Mar 2016 02:52 PM |
FindFirstChild returns what you're trying to find or nil, meaning the code will still run. But if it returned nil, target will be nil. You got to check if target is nil or not.
local target = game.Workspace.PlayerDueling:FindFirstChild(Challengee) if target then target.Event1:FireServer() --Launch Event else print('couldn't find target!') end |
|
|
| Report Abuse |
|
|
Locard
|
  |
| Joined: 13 Apr 2014 |
| Total Posts: 3516 |
|
| |
|
| |
|
| |
|