Making new commands

---Kill Player
game.Players.PlayerAdded:Connect(function(Player)
	if Player:GetRankInGroup(15423675) >= 245 then
		Player.Chatted:Connect(function(Command)
			local SplitCommand = Command:split(" ")
			if SplitCommand[1] == ":kill" or SplitCommand[1] == ":Kill" then
				local TargetedPlayer = SplitCommand[2]
				local Name = game.Players:FindFirstChild(TargetedPlayer)
				Name.Character.Head:Destroy()
			end
		end)
	end
end)
---Kill Player

Was following a tutorial on YT and when I tried adding new command by doing else if statements I faced some issues. In the video he said to copy the ENTIRE code again and paste it. Which I was thinking that it would be TOO MUCH code. Is there any other way to add more commands?? Without copying and pasting the entire script over and over for each command?

1 Like

So are you looking to make this so you do not need to make it copy and pasted? I might have a solution? So like, you can make a list of commands?

Hmmmm, what do you mean by that.

You want it to be able to run, without you copying and pasting the entire code over and over again.

game.Players.PlayerAdded:Connect(function(Player)
	if Player:GetRankInGroup(14126926) >= 254 then
		Player.Chatted:Connect(function(Command)
			local SplitCommand = Command:split(" ")
			if SplitCommand[1] == ":kill" or SplitCommand[1] == ":Kill" then
				local TargetedPlayer = SplitCommand[2]
				local Name = game.Players:FindFirstChild(TargetedPlayer)
				Name.Character.Head:Destroy()
			elseif SplitCommand[1] == ":Rename" or SplitCommand[1] == ":rename" then
				local TargetedPlayer = SplitCommand[2]
				local Name = game.Players:FindFirstChild(TargetedPlayer)
				Name.Character.HumanoidRootPart.Name = "NameOfPlayer"
			else
				warn("Something happened where the player has either not chatted the correct command, or another error has occured! Please try again!")
			end
		end)
	end
end)

i changed a few things you can see. you can create an infinite amount of elseif statements, without making it error. Just make sure you have an else statement that calls an warn message. do it as i did and u can create any amount of commands!

1 Like

Question, can I do it without else if statements??? Here’s what I just found out rn.

game.Players.PlayerAdded:Connect(function(Player)
	if Player:GetRankInGroup(15423675) >= 245 then
		Player.Chatted:Connect(function(Command)
			local SplitCommand = Command:split(" ")
			--Kill Player
			if SplitCommand[1] == ":kill" or SplitCommand[1] == ":Kill" then
				local TargetedPlayer = SplitCommand[2]
				local Name = game.Players:FindFirstChild(TargetedPlayer)
				Name.Character.Humanoid.Health = 0
			end
			--Kill Player
			
			--Infinte Health
			if SplitCommand[1] == ":god" or SplitCommand[1] == ":God" then
				local TargetedPlayer = SplitCommand[2]
				local Name = game.Players:FindFirstChild(TargetedPlayer)
				Name.Character.Humanoid.Health = 10000000000
			end
			--Infinte Health

Would it still work without the else if statement?

Since it worked with just putting else

No. Because if statements can be defined with more code, as elseif statements can just define some of the same variables if you want that! If you find my post useful, please make my post the solution of this topic if you found it helpful

1 Like

Btw their is a special InstanceClass made for commands never tried it out tho

Huh, wait I’m confused. Can I just keep each command starting with a else statement? since I understand it better, and it works rn.

Doesn’t really work. Kinda can’t be customized. A few commands and something will work. Not really a way to make it so only specific users can use it

Oh don’t worry I made it group working. So I think it should be ok… Also what is the warn for?? I think it might be to print to the output, but people can’t see the output since they ain’t studio. So what’s the real point of warn???

Prints don’t override an error. As the warn does. You don’t need to keep it. Just something to make life easier lol. course of habit, sorry! I just like to be able to find my correct errors since I specialize in programming!

So, you need to use elseif. Because you cannot have more than one else statement. That’s why we keep the warn at the bottom, so their is something besides elseif statements!

So I can only use 1 else in a if statement??? and the rest else ifs statements?

2 questions. So only 1 else can be in a if statement?

Also the image shows there’s an error with the code. What should I do?

I don’t know what the error is. Do you have the ends both there?

Use elseifs. Usually, when making an admin system, it is done by ModuleScripts and requiring them on each chat which is determined by another ModuleScript. Your error means that you missed to close an if statement with an end. This is not the right way of doing an admin system, just so you know.

1 Like

I’m using a Script. I’m just looking for 1 answer. I made my first command using a if statement. For my 2, 3, 4, etc. command do I use else or else if statements. I’m looking for 1 answer.