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

How to make the Kill script works with contractions and different size symbols!?!

Script1

local prefix = "/" --The prefix that will be used


game.Players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(msg)
        if msg:sub(1,6) == prefix.."kill " then --The first example you gave this would be correct
            local target = game.Players:FindFirstChild(msg:sub(7)) --There is another way to do this but this is the simplest way, but you need to find the player after the command was used. This is why sub will be used.
            if target then --Check if the player is actually there
                local char = target.Character --Make sure they have a character
                if char then
                    char:FindFirstChild("Humanoid").Health = 0
                end
            end
        end
    end)
end)



Script2

game.Players.PlayerAdded:Connect(function(player)
 player.Chatted:Connect(function(message)
  if message == ("/kill me") then
	for i,v in pairs(game.Players:GetChildren()) do
v.Character.Humanoid.Health = 0
end
end
end)
end)

Im trying to make it work even if u say like /KiLL Lolamtic or like /kill Lo or /KiLL LOLAmTic

1 answer

You could make an autofill by doing the following:

local target = string.lower(msg:sub(8)) --Remember, there is a space between kill and the player name.
for _, player in pairs(game:GetService('Players'):GetPlayers()) do
	if string.sub(string.lower(player.Name), 8, string.len(target)) == target then
		player.Character.Humanoid.Health = 0
		break
	end
end

What this does, is shorten the player's name to the amount of characters you provided to find the character, and then tries to match it with the player name you provided. These names are lowered in case their name has inconsistent capitalization. Also, remember white spaces count as a character, so you will have to start from the eighth letter of the command. Hope this helps!

1 comment

0

It will show an error and u ignored script 2

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