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

What is wrong with my vey simple math?

I am trying to make a script that kills the person you are chatting about(admin command). It works fine until I tried to add a part that lets you shorten names. I am pretty sure I did something wrong with my math since there are no errors.

local Player=game.Players.LocalPlayer
Player.Chatted:connect(function(Text)
	if string.sub(Text,1,4)=="Kill" or "kill" or "KILL" then
		for i,v in pairs(game.Players:GetChildren()) do
			for i=7,tonumber(string.len(v.Name)),1 do
				local Length=tonumber(string.len(Player.Name))
				if string.sub(Text,6,i)==string.sub(v.Name,1,Length-(i-6)) then
--I think its something above and between[                               ]
				v.Character.Humanoid.Health=0
				end
			end
		end
	end
end)

--[["Kill tuma"
     123456789]]

1 answer

✓ Accepted answer

Well, first of all, you should use the string.match method, for finding partial names.. and secondly, check the keyword with a string.lower method, so that you don't have to put every combination of the word(:

local Player = game.Players.LocalPlayer

Player.Chatted:connect(function(Text)
	if Text:sub(1,4):lower() == "kill" then
		local plrKey = Text:sub(6):lower()
		for i,v in pairs(game.Players:GetPlayers()) do
			if v.Name:lower():match(plrKey) then
				v.Character:BreakJoints()
			end
		end
	end
end)

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