--Scripted by Electrowizard12312-- local Players = game:GetService("Players") local cashCommand = "/give " -- local function onOwnerChatted(player, message) if message:sub(1, cashCommand:len()):lower() == cashCommand:lower() then local name = message:sub(cashCommand:len() + 1) local player = Players:FindFirstChild(name) local amount = message:sub(cashCommand:len()+ name + 1 ) if player then player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + amount print("The creator gave "..name.." "..amount.." cash.") else print("Couldn't find player!") end end end -- local function onPlayerAdded(player) if player.UserId == 586053124 then player.Chatted:Connect(function (...) onOwnerChatted(player, ...) end) end end -- for _, player in pairs(Players:GetPlayers()) do onPlayerAdded(player) end Players.PlayerAdded:Connect(onPlayerAdded) -- Scripted by Electrowizard12312
This script is supposed to give cash to a player when someone chats /give player amount, but for some reason, it is considering local amount as nil(line 9) and it doesn't give any cash(No output). But if I make line 9 as 1000 or any value, it works.
How do I fix this?
local function onOwnerChatted(player, message) message=message:lower() local cmd,arg1,arg2=unpack(message:split(" ")) if cmd~="/give" or not arg1 or not arg2 then return end arg2=tonumber(arg2) if not arg2 then return end local target for _,v in ipairs(Players:GetPlayers())do if v.Name:lower():sub(1,arg1:len())==arg1 then target=v break end end if target then target.leaderstats.Cash.Value+=arg2 end end