Hello, so I'm currently making a script that prints out 1. Killer Name 2. Killer Weapon
Whenever I go to test it I get an error in my output saying ****Workspace.Script:12: attempt to index local 'Weapon' (a nil value)**** How would I go about fixing this? Here's my full script
01 | Players = game:GetService( "Players" ) |
02 | Players.PlayerAdded:connect( function (Player) |
03 |
04 | Player.CharacterAdded:connect( function (Character) |
05 | local Humanoid = Character:WaitForChild( "Humanoid" ) |
06 | Humanoid.Died:connect( function () |
07 | if Humanoid:FindFirstChild( "creator" ) ~ = nil then |
08 | local Killer = Humanoid.creator.Value |
09 | local Weapon = Killer:FindFirstChildOfClass( "Tool" ) if true then |
10 | end |
11 | print (Killer.Name) |
12 | print (Weapon.Name) |
13 | end |
14 | end ) |
15 | end ) |
16 | end ) |
I'm not too familiar with the creator tag but I believe the issue is that creator.Value is the actual player rather than the player's character. Try adding .Character to the end of line 8 like so:
1 | local Killer = Humanoid.creator.Value.Character |
The player's humanoid has a creator
value, what type of variable is it?
If it's an object value, then it's referring to the player in game.Player
The way to fix it is to add a string value and set it as the killer, so replace it with workspace[creator.Value]
Hoped this helps!