Problem with stat admin command

Hello Devs!

I’m making Admin commands but I want to make some arguments normal.
I uses string.lower() and it makes all string small but in stat command when I type:
/add {username} {StatType} {Amount}
StatType is small and script can’t find a stats.

Here is script:

local commands = {}

local prefix = "/"

local admins = {
	226087810; -- R05HX
	1583088521; -- Simongracz
}

local function findPlr(name)
	for i, player in pairs(game.Players:GetPlayers()) do
		if string.lower(player.Name) == name then
			return player
		end
	end
	return nil
end

local function isAnAdmin(plr)
	for _, v in pairs(admins) do
		if v == plr.UserId then
			return true
		end
	end
	
	return false
end



-- Add Stat Value 
commands.add = function(sender, arguments)
	local PlrToGive = arguments[1]
	local Currency = arguments[2]
	local Amount = arguments[3]
	
	if PlrToGive and Currency and Amount then
		local PlrToG = findPlr(PlrToGive)
		
		if PlrToG then
			PlrToG.leaderstats[Currency].Value += tonumber(Amount)
		end
	end
end

game.Players.PlayerAdded:Connect(function(plr, arguments)
	if isAnAdmin(plr) then
		plr.Chatted:Connect(function(msg,recipient)
			msg = string.lower(msg) -- makes every string small

			local splitString = msg:split(" ")

			local slashcmd = splitString[1]

			local cmd = slashcmd:split(prefix)

			local cmdName = cmd[2]

			if commands[cmdName] then
				local arguments = {}

				for i = 2, #splitString, 1 do
					table.insert(arguments, splitString[i])
				end


				commands[cmdName](plr,arguments)
			end
		end)
	end
end)

Output error: speed is not a valid member of Folder "Players.R05HX.leaderstats"

2 Likes

I think you should keep 2 strings of message: the original and lower. For example if you typed “/add Roblox Speed 20” the two strings will be “/add Roblox Speed 20” and “/add roblox speed 20”
You overwrited the message string on " msg = string.lower(msg) – makes every string small"

1 Like

You could loop thru the leaderstats and lower the childrens names and if the name is same as currency then currency = not lowered name, or you could have a table with all the currencies and do the same, though these 2 are a bit hacky ways… Alternatively if the currency names all have first letter uppercased, you could just make the first letter uppercase.

I tried but It don’t works and now I don’t have any idea how to do it… or i did something wrong

Can you try this?

game.Players.PlayerAdded:Connect(function(plr, arguments)
	if isAnAdmin(plr) then
		plr.Chatted:Connect(function(msg,recipient)
			msg2 = string.lower(msg) -- makes every string small

			local splitString = msg2:split(" ")
			local splitString2 = msg:split(" ")
			local slashcmd = splitString[1]

			local cmd = slashcmd:split(prefix)

			local cmdName = cmd[2]

			if commands[cmdName] then
				local arguments = {}

				for i = 2, #splitString2, 1 do
					table.insert(arguments, splitString2[i])
				end


				commands[cmdName](plr,arguments)
			end
		end)
	end
end)

When I will remove msg = string.lower(msg)
I will get the same thing but when I’m typing: /add R05HX Speed 100 script do nothing but when I’m typing: /add r05hx Speed 100 script gives me a 100 speed but I want to use lowered and not lowered username.