Make a print command and make it print something and then use that command in chat
what do i do with them then?
local Commands = {
ban = function(player, victim)
local DataStoreService = game:GetService("DataStoreService")
local BanDataStore = DataStoreService:GetDataStore("BanData")
local success, errormessage = pcall(function()
BanDataStore:SetAsync(victim.UserId, true)
end)
if success then
print "Player is now banned."
end
victim:Kick("You have been permanently banned.")
end;
kill = function(player, victim)
end;
to = function(player, victim)
player.Character:MoveTo(victim.Character.Head.Position)
end;
bring = function(player, victim)
victim.Character:MoveTo(player.Character.Head.Position)
end;
grow = function(player, victim, value)
if victim.Character:FindFirstChild("Growth") then
victim.Character.Growth.Value = value
end
end;
}
return Commands
Make a print command and then use that command in chat
test = function(...)
print(...)
end
then in chat say â:test asd 123â
kill = function(player, victim)
print"killed"
end;```
prints now.
it prints twice actually too af svs vxcv xc v
got it, now it doesnât run the commands onto players tho
local Commands = {
ban = function(player, victim)
local DataStoreService = game:GetService("DataStoreService")
local BanDataStore = DataStoreService:GetDataStore("BanData")
local success, errormessage = pcall(function()
BanDataStore:SetAsync(victim.UserId, true)
end)
if success then
print "Player is now banned."
end
victim:Kick("You have been permanently banned.")
end;
kill = function(player, victim)
print"killed"
end;
to = function(player, victim)
player.Character:MoveTo(victim.Character.Head.Position)
end;
bring = function(player, victim)
victim.Character:MoveTo(player.Character.Head.Position)
end;
grow = function(player, victim, value)
if victim.Character:FindFirstChild("Growth") then
victim.Character.Growth.Value = value
end
end;
}
return Commands
Earlier I told you to make a FindPlayer function inside of the commands module.
Here you go Lol
local Players = game:GetService'Players'
local function GetPlayers(Name)
Name = string.lower(Name)
local Return = {}
for i, Player in pairs(Players:GetPlayers()) do
if string.find(string.lower(Player.Name), Name) then
table.insert(Return, Player)
end
end
return Return
end
local Commands = {
kill = function(player, victim)
local Players = GetPlayers(victim)
for i, Player in pairs(Players) do
if Player.Character then
Player.Character:BreakJoints()
end
end
end;
}
return Commands
it doesnt work, is that the victim or the player?
It works, player
is the caller of the function, and Player
is the target that it finds, if you want you can rename Player
to victimPlayer
or something
error: 15:05:27.321 ServerScriptService.Admin.Commands:35: attempt to index nil with âHumanoidâ - Server - Commands:35
(on the kill command line)
local function GetPlayers(Name)
Name = string.lower(Name)
local Return = {}
for i, victimPlayer in pairs(Players:GetPlayers()) do
if string.find(string.lower(victimPlayer.Name), Name) then
table.insert(Return, victimPlayer)
end
end
return Return
end
================================
kill = function(player, victim)
local victimPlayer = GetPlayers(victim)
victimPlayer.Character.Humanoid.Health = 0
print"killed"
end;
Means it doesnât exist use
victim.Character:WaitForChild("Humanoid").Health = 0
instead of
âvictim.Character.Humanoid.Health = 0â
Since GetPlayers
is returning a table, wouldnât you want to iterate through the return via a generic for?
EDIT
His GetPlayers
method is returning the player with the matching name
He needs to iterate through the table returned in his command.
It already iterates through the table in the GetPlayers function
Good admin but may needs loads of commands otherwise not many people will use it.
Give it some guis as well maybe.
what do i do then?
asdasdsadsc
In your command code, victimPlayer
is the return value for the matched players - you could use a generic for to iterate through it and kill the players from there.
kill = function(player, victim)
local victimPlayer = GetPlayers(victim)
for i, v in ipairs(victimPlayer) do -- Iterates through the matched player table returned
if v.Character and v.Character:FindFirstChild("Humanoid") then -- Check for the character and humanoid for the player
v.Character.Humanoid.Health = 0 -- Kill the player
end
end
print"killed"
end;
As @TheeDeathCaster said, GetPlayers(Name)
returns a table of all players that got matched by âNameâ
For example: letâs say there are three players, Bob
, Bob1
, and Jeff2
. If you do
local victimPlayers = GetPlayers("bob")
then victimPlayers
would be a table containing all the player objects that the GetPlayers
function found by comparing names.
-- victimPlayers table
{
game.Players.Bob,
game.Players.Bob1
}