---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?
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!
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
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
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!
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.
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.