I am trying to achieve a way to give a certain player a certain amount of levels, or points, anything that is hardcoded inside the script.
Here is my sample code -
--[[
@author TwinPlayzDev_YT
@since 3/25/2021
This script will let a admin, give a certain player a certain ammount of a leaderstat.
--]]
--[ SERVICES ]--
local Players = game:GetService("Players")
--[ MAIN LOCALS ]--
local command = "/give ([%w_]+)" or "/add ([%w_]+)" --this is a string pattern that should match any player username
local Admin = 90228414 -- allowed person
--[ FUNCTIONS ]--
game.Players.PlayerAdded:Connect(function(localplr)
localplr.Chatted:Connect(function(msg)
if localplr.UserId == Admin then
local subjectName = msg:match(command + "%d") -- checking to see if it matches text
if subjectName then
local subject = game.Players:FindFirstChild(subjectName)
if subject then
local level = subject.Minutes.Value
-- give level here
end
end
else
print("not allowed")
end
end)
end)
What I need help with is wondering how can I add the amount of points or levels at the end of /give (PLAYER) then (NUMBER)
So
atm, I have !give stringpattern that works to get a players name.
If you have any idea how I could attempt to get the certain amount at the end of the command, I couldn’t figure out the right string patterns.
1 Like
The best tutorial to make an admin commands script: https://www.youtube.com/watch?v=ZJE_xTzOdLs
Because to get the amount of thing to give you need multiple arguments.
2 Likes
Use string.split
for that
2 Likes
function check(plr)
local length = string.len(plr)
for i, v in pairs(game.Players:GetChildren()) do
if string.lower(plr) == string.lower(string.sub(v.Name, 1, length)) then
return true and v.Name
break
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if plr.UserID == 90228414 then
local nmsg = msg:split()
if nmsg[1] == "/give" or nmsg[1] == "/add" then
local r = msg[2]
local amount = msg[3]
if check(r) then
if tonumber(amount) then
game.Players[v.Name].leaderstats.Coins.Value += tonumber(amount)
end
end
end
end
end)
end)
3 Likes
Do this:
local MsgPlr = string.split(msg, " ")
local Plr = MsgPlr[2]
local Giving = MsgPlr[3]
if game.Players:FindFirstChild then
Plr = game.Players[Plr]
if Giving ~= nil then
Plr.leaderstats.level += tonumber(Giving)
end
end
Any way you can get this code to work?
I tried using Split, but I don’t know if im using it in the right way.
Heres an Error :
ServerScriptService.LevelCommand2:34: attempt to perform arithmetic (add) on number and nil
--[ SERVICES ]--
local Players = game:GetService("Players")
--[ MAIN LOCALS ]--
local command = "/give ([%w_]+)" or "/add ([%w_]+)" --this is a string pattern that should match any player username
local Admin = 90228414 -- allowed person
--[ FUNCTIONS ]--
game.Players.PlayerAdded:Connect(function(localplr)
localplr.Chatted:Connect(function(msg)
if localplr.UserId == Admin then
local subjectName = msg:match(command) -- checking to see if it matches text
local nmsg = subjectName:split()
if subjectName then
local subject = game.Players:FindFirstChild(subjectName)
if subject then
local level = subject.leaderstats.Minutes.Value
local amount = nmsg[2]
level += amount
end
end
else
print("not allowed")
end
end)
end)
1 Like
Try changing this:
local nmsg = string.split(subjectName, " ")
2 Likes