Problem with giving currency command

Hello devs!

I have problem with giving currency command. I’m using values which starts with big letter
(ex: Cash) but in my command handler everything in command is turning to lower case
(ex: Cash → cash) and when I’m using command it says:
cash is not a valid member of Folder "Players.R05HX.leaderstats"

here is my script:

--//  add currency command
commands.add = function(sender, arguments)
	local PlrToGive = arguments[1]
	local Folder = arguments[2]
	local Currency = arguments[3]
	local Amount = arguments[4]
	
	if PlrToGive and Folder and Currency and Amount then
		local PlrToG = findPlr(PlrToGive)
		Currency = string.format(Currency)
		if PlrToG then
			PlrToG[Folder][Currency].Value += tonumber(Amount)
		end
	end
end

--// Command Handler
game.Players.PlayerAdded:Connect(function(plr, arguments)
	if isAnAdmin(plr) then
		plr.Chatted:Connect(function(msg,recipient)
			msg = string.lower(msg)
			
			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)

Well,

You used string.lower, if you remove that it should work

I know but I want to use string.lower(msg) because I don’t need to type command perfectly.

Okay, well in that case if all of your currency names start with a capital letter then do this:

Make this function,

function firstUpper(str)
    return (str:gsub("^%l", string.upper))
end

Then change:

local Currency = firstUpper(arguments[3])

Thank you! Now it’s works correctly!
I need to learn more about strings.

1 Like