Need help with chat command

Hello. I’m currently trying to make a cash giver script, but I keep getting an error (shown below). Any help would be greatly appreciated. Thanks.

local cashCmd = ":cash "
local levelCmd = ":level "
local ownerId = 219993365

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if player.UserId == ownerId then
			if msg:sub(1, cashCmd:len()):lower() == cashCmd:lower() then
				local username = msg:sub(cashCmd:len()+1):lower()
				local cashAmount = msg:sub(username:len()+1):lower()
				local playerName = game.Players:GetChildren(username)
				playerName.leaderstats.Cash.Value = cashAmount
			end
			if msg:sub(1, levelCmd:len()):lower() == levelCmd:lower() then
				local levelAmount = msg:sub(levelCmd:len()+1):lower()
				player.leaderstats.Level.Value = levelAmount
			end
		end
	end)
end)

image_2023-10-30_121258045

local cashCmd = ":cash"
local levelCmd = ":level"
local ownerId = 219993365

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if player.UserId == ownerId then
			local split = msg:split(" ")
			local prefix,username,amount = split[1],split[2],split[3]
			if prefix == cashCmd then
				local username = game.Players:FindFirstChild(username)
				if username then
					username.leaderstats.Cash.Value += amount
				end
			end
		end
	end)
end)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.