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

How can I make an admin command for changing leaderstats?

Hello,

I am making a game that has 3 leaderstats (TimeAlive, TopTime, and Kills) and I am wondering how I could create an admin command that would give certain people permission to use it.

For example:

:change PlayerName TimeAlive 10000

Output: Changes PlayerName's TimeAlive leaderstat to 10000.

I'm going to have mods and admins in my game, so I want to make sure that I can give it to others as well.

Thank you, epioma

1 comment

0

This question is way too specific, basically a request. However, I recommend you start with this https://www.youtube.com/watch?v=ZJE_xTzOdLs

1 answer

You can use the chatted event to detect what a player says, then using the string.find() and string.split() function to cut up the chat message so you know if it is a command or not and applying the command

https://developer.roblox.com/en-us/api-reference/event/Player/Chatted

https://developer.roblox.com/en-us/api-reference/lua-docs/string

For example;

player.Chatted:Connect(function(msg) -- assuming you already have the player
	if string.find(msg,":change") then -- if they go into the msg and find ":change" then
		local cmd = string.split(msg," ")[1] -- getting the first word that is separated by a space in the msg
		local plrName = string.split(msg," ")[2] -- second one
		local value = string.split(msg," ")[3] -- third
		local changeTo = string.split(msg," ")[4] -- fourth
		local success,err = pcall(function() -- use a pcall to determine if it was valid
			game.Players:FindFirstChild(plrName):FindFirstChild(value).Value = changeTo
		end)
		if success then -- if it worked
			print("successful!") -- successful! yay!
		else -- if not success
			print("error, something went wrong")
			warn(err) -- prints the error message (err)
		end
	end
end)

You can find information for pcalls() and other lua globals here: https://developer.roblox.com/en-us/api-reference/lua-docs/Lua-Globals

Hope this helps and if not then maybe it can lead you in the right direction

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