game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Message)
local Command = string.split(Message, " ")
local PayCommand = string.lower(Command[1])
if PayCommand == "/pay" then
local PaidPlayerName = Command[2]
local Amount = Command[3]
local PaidPlayer = game.Players:FindFirstChild(PaidPlayerName)
if PaidPlayer ~= Player.Name then --If the paid player's name isn't the paying player's name, then
if Player.leaderstats.Cash.Value >= Amount then --Checking if the player has enough money (This is the part where I begin to get the error)
if PaidPlayer.leaderstats then --If the second word is actually a player and they have leaderstats, then
PaidPlayer.leaderstats.Cash.Value = PaidPlayer.leaderstats.Cash.Value + Amount
Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value - Amount
end
end
end
end
end)
end)
I have been searching for an answer for hours but could not find one.
game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Message)
local Command = string.split(Message, " ")
local PayCommand = string.lower(Command[1])
if PayCommand == "/pay" then
local PaidPlayerName = Command[2]
local Amount = tonumber(Command[3])
local PaidPlayer = game.Players:FindFirstChild(PaidPlayerName)
if PaidPlayer ~= Player.Name then --If the paid player's name isn't the paying player's name, then
if Player.leaderstats.Cash.Value >= Amount then --Checking if the player has enough money (This is the part where I begin to get the error)
if PaidPlayer.leaderstats then --If the second word is actually a player and they have leaderstats, then
PaidPlayer.leaderstats.Cash.Value = PaidPlayer.leaderstats.Cash.Value + Amount
Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value - Amount
end
end
end
end
end)
end)
A bunch of other random issues with the cleanliness of your code:
Don’t use game.Players, use game:GetService("Players"), since it doesn’t rely on the name of the service instance.
It might be worth making Player.leaderstats.Cash and PaidPlayer.leaderstats variables just to make the code a bit cleaner.