so I’ve been making this custom admin script and so far this is what i have
game:GetService('Players').PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Message)
if string.sub(Message, 1,11) == "/e heal" and whitelist[Player.Name] then
local targetedplayer = Player.Name
local Health = Player.Character.Humanoid.Health
local amount = Health.Value
Player.Character.Humanoid.Health += 100
for i, v in pairs(game:GetPlayers()) do
if v.name == targetedplayer
then v.Character.Humanoid.Health += amount
end
end
end
end)
end)
only problem is that i dont know how to define amount ex: /e heal 1-100
also i dont know if the /e heal (player) works only thing i know that works is the /e heal without specifying who and an amount
so how would i specify an amount and specify a player to receive the heal
Like @huh_crazy said, use string.split(msg, sep) for admin commands.
I’ll run you through a quick tutorial for your use case (not I’m on mobile so there might be a few typos also I won’t type out the charted event so everything I’m showing you goes in the chatted event)
Ok, so step one, split the message into the parts.
local split = string.split(Message, " ")
if split[1] ~= "/e" then return end
local command = split[2]
local plrName = split[3]
local amount = split[4]
Now all you have to do is validate the passed data and add the stats
if command == "heal" then
local plr = game.Player:FindFirstChild(plrName)
if plr then
if tonumber(amount) then
amount = tonumber(amount)
local char = plr.Character or player.CharacterAdded:Wait()
char.Health += amount
end
end
end
local Game = game
local Players = Game:GetService("Players")
local Whitelist = { --Whitelisted users (user IDs).
[1] = true,
[Game.CreatorId] = true
}
local function OnPlayerAdded(Player)
local function OnPlayerChatted(Message)
if not Whitelist[Player.UserId] then return end
local Name, Value = string.match(string.lower(Message), "^/e%sheal%s([%w_]+)%s(%d+)")
if not (Name and Value) then return end
local NamedPlayers = {}
for _, Player in ipairs(Players:GetPlayers()) do
if not string.match(string.lower(Player.Name), "^"..Name) then continue end
table.insert(NamedPlayers, Player)
end
for _, NamedPlayer in ipairs(NamedPlayers) do
local Character = NamedPlayer.Character
if not Character then continue end
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
if (not Humanoid) or Humanoid.Health <= 0 then continue end
Humanoid.Health += Value
end
end
Player.Chatted:Connect(OnPlayerChatted)
end
Players.PlayerAdded:Connect(OnPlayerAdded)