String.sub(message:lower(), 1, 8) not working by SOME commands

Im working on Baums Admin v.2 and some commands are not working!

Code

game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(message)

if string.sub(message:lower(),1 ,8) == Settings.CommandsStart.."kill me" then
					plr.Character.Humanoid.Health = 0
				elseif string.sub(message:lower(), 1, 9) == Settings.CommandsStart.."kill all" then
					for i,v in pairs(game.Players:GetChildren()) do
						if v.Character.Humanoid then
							v.Character.Humanoid.Health = 0
						end
					end
				elseif string.sub(message:lower(),1,4) == Settings.CommandsStart.."kill" then
					plr.Character.Humanoid.Health = 0
				end

and no Errors!

Have a great day!

1 Like

You missed 2 end)'s to end your Events

game.Players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(message)
        if string.sub(message:lower(),1 ,8) == Settings.CommandsStart.."kill me" then
			plr.Character.Humanoid.Health = 0

		elseif string.sub(message:lower(), 1, 9) == Settings.CommandsStart.."kill all" then
			for i,v in pairs(game.Players:GetChildren()) do
				if v.Character.Humanoid then
					v.Character.Humanoid.Health = 0
				end
			end

		elseif string.sub(message:lower(),1,4) == Settings.CommandsStart.."kill" then
			plr.Character.Humanoid.Health = 0
        end
    end)
end)

Maybe this?

game:GetService("Players").PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(message)
		if string.sub(string.lower(message),1 ,8) == Settings.CommandsStart .. "kill me" then
			plr.Character.Humanoid.Health = 0
		elseif string.sub(string.lower(message), 1, 9) == Settings.CommandsStart .. "kill all" then
			for i,v in pairs(game:GetService("Players"):GetPlayers()) do
				if v.Character.Humanoid then
					v.Character.Humanoid.Health = 0
				end
			end
		elseif string.sub(string.lower(message),1,4) == Settings.CommandsStart .. "kill" then
			plr.Character.Humanoid.Health = 0
		end
	end)
end)
1 Like

I have that in the script and no ERRORS.

Not exactly as you included in your OP, but okay

Try this and see what Outputs back:


game.Players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(message)
        local FormattedMessage = string.sub(message:lower(), 1, 8)
        print(FormattedMessage)
        if FormattedMessage == Settings.CommandsStart.."kill me" then
			plr.Character.Humanoid.Health = 0

		elseif string.sub(message:lower(), 1, 9) == Settings.CommandsStart.."kill all" then
			for i,v in pairs(game.Players:GetChildren()) do
				if v.Character.Humanoid then
					v.Character.Humanoid.Health = 0
				end
			end

		elseif string.sub(message:lower(),1,4) == Settings.CommandsStart.."kill" then
			plr.Character.Humanoid.Health = 0
        end
    end)
end)
1 Like

I can not use

local FormattedMessage = string.sub(message:lower(), 1, 8)

i have long and short cmds(commands)

add print(message)

it prints:

/kill me

You still should just check for that specific command alone & see if it works or not, or just lowering the string using string.lower() and not subbing it

Also I’m assuming that Settings.CommandStart is a prefix for the command?

module.CommandsStart = "/"

And

string.lower

is not working too.

add print(string.sub(string.lower(message), 1, 8) == Settings.CommandsStart … “kill me”) and execute /kill me command

Doing string.sub(whatever, 1, 8) will trim it down to the first 8 characters. Just trim it down to the length of the command you’re comparing to by changing the 8.

1 Like

btw the /kill me command is working but /kill all not

if string.sub(message:lower(), 1, 15) == Settings.CommandsStart.."Bubble Chat me" then
					local Message = string.sub(message:lower(), 17)
					Chat:Chat(plr.Character, Message)
				end

Thats in the script too

Change this

with this:

elseif string.sub(string.lower(message), 1, 9) == Settings.CommandsStart .. "kill all" then
	for _, player in pairs(game:GetService("Players"):GetPlayers()) do
		local hum = player.Character and player.Character:FindFirstChild("Humanoid")
		if hum then hum.Health = 0 end
	end
for i,v in pairs(game.Players:GetPlayers())

is working too
AND btw i think was a bug its working now