Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I make an admin command that adds to a leaterstat??

So it would be like

:add(stat name) players amount --it automatically knows what stat it needs to be added to.

I use the admin Basic Admin Essentials 2.0 so if you know how to make a custom command for that or if I make a totally different script and have an admin function.

Sincerely Toxi.

1 comment

0

We aren't free model support; you should make an attempt

2 answers

✓ Accepted answer

What you could use is String.match() to place a string into a table into separate arguments. In your case it would be a little something like this:

cmdPrefix = '.'

local admins = {
'AnAdminUsername123', -- username
24829482, -- userid 
}

function checkAdmin(Player)
	for _,v in pairs(admins) do
		if type(v) == 'string' and v == Player.Name then
			return true
		elseif type(v) == 'number' and v == Player.UserId then
			return true
		end
	end
	return false
end

function getPlayer(givenString)
	if not givenString then return end
	local victim = nil
	for _,Player in pairs(Players:GetPlayers()) do
		if Player.Name:lower() == givenString:lower() then return Player end
		if Player.Name:sub(1, #givenString):lower() == givenString:lower() then
			victim = Player
		end
	end
	return victim
end

Player.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Message)
		if checkAdmin(Player) then -- check if player is admin	
			local args = {} -- table to store arguments
			for arg in Message:gmatch("%S+") do -- look for argument per space in string
				table.insert(args, arg) -- insert into table
			end
			
			if args[1]:lower() == cmdPrefix..'change' then -- check for command
				local victim = getPlayer(args[2])
				if victim then
					local stat = args[3]
					if victim.leaderstats:FindFirstChild(stat) ~= nil then
						stat = victim.leaderstats[args[3]]
					end
					local value = args[4]
					if type[value] == 'number' then -- check if argument is number
						stat.Value = value -- change value
					end
				end
			end
			
		end
	end)
end)

So let's say an admin would say .change (player) (stat) (value) it would go through all the checks and if they all pass, it should change the players value. Obviously, you can change the if statements accordingly for your script but this is just a template.

I didn't really check this since I am in a hurry so if there are any errors please let me know and I shall try to fix them.

3 comments

0

Thank you.

0

Would I be able to edit this so it is just "change player value" how would I do that?

0

I don't think you can do changer player value, because the game would need to know which value it has to change.

This discussion is preserved as it was. New answers, comments, and votes are closed.