Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.


2 comments

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.

0

Oh, alright. Have fun!

This discussion is preserved as it was. New answers, comments, and votes are closed.