Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

I am trying to make a "Kill" Chat Command and I don't want to copy off Khol or Person299?

Asked by
PolyyDev 214 Moderation Voter
6 years ago
Edited 6 years ago

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:

local admins = {"Ki_ngPhantom"}
local banned = {}
local prefix = "*"
game.Players.PlayerAdded:connect(function(plr)
    plr.Chatted:connect(function(msg)
        if msg:lower() == prefix.."version" then
            print("0.01")
        end
        if msg:lower() == prefix.."suicide" then
            plr.Character.Humanoid.Health = 0
        end
        if msg:lower():sub(1, 6) == prefix.."kill " then
            game.Players:FindFirstChild(msg:lower():sub(6)).Character.Humanoid.Health = 0
        end
    end)
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

1 answer

Log in to vote
2
Answered by
Sur4y 40
6 years ago

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:

if string.sub(msg, 0, 6) == (prefix.."kill ") then
    local findPlayer = game.Players:FindFirstChild(string.sub(msg, 7))
    findPlayer.Character.Humanoid.Health = 0
end

I've tested this in studio, it worked.Tell me if you run into problems.


If it works, tag my answer as answered.


0
Thanks, that works! And in the script it didn't set "Humanoid" to 0. I don't know why it showed up like that. PolyyDev 214 — 6y
0
Oh, alright. Have fun! Sur4y 40 — 6y
Ad

Answer this question