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

Can you provide a fix for my kill command that is not working?

		~~~~~~~~~~~~~~~~~
if msg:sub(1, 6) == prefix .. "kill " then
				
				target = game.Players:FindFirstChild(msg:sub(7))
				character = target.Character
				
				if character then
					character.Humanoid.Health = 0
				end
			end


Does anyone get the error in this, because for me it does not display an error but just kind of does nothing, can anyone provide a fix?

2 answers

✓ Accepted answer

I have noticed a few things a few things which should really be added to the script to help you locate the player and prevent errors.

First thing I noticed was there was no if statement to check if a player was found, if there wasn't anything found without and if statement, it'd still run through the code and give you an error.

Also, the second thing I noticed is you were not using string manipulation in order to find a player without the burden of Cap Sensitivity. Here is an attempt to help you overcome your problems.


Players = game:GetService('Players')

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if string.sub(msg,1,5):lower() == 'kill ' then -- using lower for cap sensitivity
			for _,player in pairs(Players:GetPlayers()) do -- loops through ingame players
				if player.Name:lower() == string.sub(msg,6) then -- using lower again for cap sensitivity 			if player.Character then
						player.Character:BreakJoints() -- kills the player
				end
			end
		end
	end)
end)

2 comments

0

thanks for the script, ill test it later!

0

The script is not working, I will answer with the script I tried so you can see if I am doing it right

    player.Chatted:Connect(function(msg)
        if string.sub(msg,1,6):lower() == prefix .. 'kill ' then -- using lower for cap sensitivity
            for _,player in pairs(Players:GetPlayers()) do -- loops through ingame players
                if player.Name:lower() == string.sub(msg,7) then -- using lower again for cap sensitivity           if player.Character then
                        player.Character:BreakJoints() -- kills the player
                end
            end
        end
    end)
end)

PS. This answer was an answer to ABritishChap to see if I used his script correctly.

1 comment

0

Assuming you've defined Player and also spelt their name correctly, that should work.

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