I have a script that handles all the chat commands when they are said the first two work but the last one, the kill cmd, doesn't seem to work. Here is the script:
01 | local admins = { "Ki_ngPhantom" } |
02 | local banned = { } |
03 | local prefix = "*" |
04 | game.Players.PlayerAdded:connect( function (plr) |
05 | plr.Chatted:connect( function (msg) |
06 | if msg:lower() = = prefix.. "version" then |
07 | print ( "0.01" ) |
08 | end |
09 | if msg:lower() = = prefix.. "suicide" then |
10 | plr.Character.Humanoid.Health = 0 |
11 | end |
12 | if msg:lower():sub( 1 , 6 ) = = prefix.. "kill " then |
13 | game.Players:FindFirstChild(msg:lower():sub( 6 )).Character.Humanoid.Health = 0 |
14 | end |
15 | end ) |
16 | end ) |
It comes up with an error message that says:
17:41:13.224 - Workspace.Ki_ngPhantoms Admin Commands.Main_Script:13: attempt to index a nil value
17:41:13.225 - Stack Begin
17:41:13.225 - Script 'Workspace.Ki_ngPhantoms Admin Commands.Main_Script', Line 13
17:41:13.226 - Stack End
First of all, you are trying to set a humanoid to "0". You got to use either .Humanoid.Health = 0 or .Humanoid:TakeDamage(Humanoid.MaxHealth).
Remove the third "if", replace it with:
1 | if string.sub(msg, 0 , 6 ) = = (prefix.. "kill " ) then |
2 | local findPlayer = game.Players:FindFirstChild(string.sub(msg, 7 )) |
3 | findPlayer.Character.Humanoid.Health = 0 |
4 | end |
I've tested this in studio, it worked.Tell me if you run into problems.
If it works, tag my answer as answered.