Trying to create my own admin commands. Not sure how to get a number out from a string and then use that for example, heal the player or damage the player. I’m wanting to make most basic things admin commands would have, then make my own antiexploit.
If anyone can help, would be much appreciated. Thanks in advance.
local admins = {"KryptonFoox"}
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
for _,a in ipairs(admins) do
if plr.Name == a then
if string.match(msg:lower(),'/kill') then
local player = msg:sub(7)
game.Players[tostring(player)].Character.Humanoid.Health = 0
elseif string.match(msg:lower(),'/god') then
local player = msg:sub(6)
game.Players[tostring(player)].Character.Humanoid.Health = math.huge
game.Players[tostring(player)].Character.Humanoid.MaxHealth = math.huge
elseif string.match(msg:lower(),'/heal') then
local player = msg:sub(5)
local toRemove = string.len(player)
local hpToGive = string.match(player,"%d")
print(hpToGive)
end
end
end
end)
end)
Have you tried adding prints() to see which line isn’t working?
On a side note
Just some tips for future reference: use pairs because ipairs is slow.
You don’t need to convert the player argument to a string because it already is one. Even with numbers in it it is typed in chat so everything is already in string format.
To correct my self I would say the new Roblox Lua VM fixed the slowness if ipairs I think so just keep on using it but it only really makes sense to use it when you have like a mixed table but I was wrong.
In addition, I would suggest using the UserId of the admins instead of their names in case they change their names and I believe there is an easier and shorter way to do the same thing.
local Admins = {UserId, UserId}
local FindPlrInAdmins = table.find(Admins, plr.UserId)
if FindPlrInAdmins ~= nil then
-- Script
end