Hello.
I am trying to achieve a /givecash [targeted username or their initials] amount command.
Issues:
Even if I say for example /givecash 1 1 or /givecash all 1 or /givecash b 1 I still receive the said amount of cash. I believe it has to do with the string matching method I am using.
Also, this line right here v.PlayerData:FindFirstChild(‘Cash’).Value = v.PlayerData:FindFirstChild(‘Cash’).Value + amount returns an issue where it does not recognize the amount and outputs it as nil.
Code:
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
message = string.split(message, ' ')
if message[1]:lower() == '/givecash' then
local target = message[2]
local amount = tonumber(message[3])
if message[3] then
if player:GetRankInGroup(13189894) >= 1 then
for _, v in pairs(game.Players:GetChildren()) do
if string.match(v.Name, target:len()) then
print('found')
v.PlayerData:FindFirstChild('Cash').Value = v.PlayerData:FindFirstChild('Cash').Value + amount
end
end
end
end
end
end)
end)