In my game I have a donation system that allows players to donate to each other. Apparently if you put in a - number you can actually steal money from the other player. How do I fix this?
Code
``
SendMoney.SendButton.MouseButton1Click:Connect(function()
Sounds.ButtonClick:Play()
local amount = tonumber(SendMoney.AmountBox.Text)
if amount then
local otherPlayer = PlayersService:FindFirstChild(SendMoney.PlayerBox.Text)
if otherPlayer then
if otherPlayer == Player then print('You cant send money to yourself') return end
if PlayerData.Drachma >= amount and amount <= 5000 then
Events.SendMoney:FireServer(amount,otherPlayer)
elseif amount > 5000 then
print("Sorry, you can only donate up to 5000!")
else
print('Sorry, you do not have enough money!')
end
else
print('Sorry"'..SendMoney.PlayerBox.Text..'" Is not a valid player!')
end
else
print('Sorry, You must enter in a valid number to send! "'.. SendMoney.AmountBox.Text .."' Is not a number!")
end
end)
Check to see if the amount > 0 - If it is, then follow your code.
SendMoney.SendButton.MouseButton1Click:Connect(function()
Sounds.ButtonClick:Play()
local amount = tonumber(SendMoney.AmountBox.Text)
if amount and amount > 0 then
local otherPlayer = PlayersService:FindFirstChild(SendMoney.PlayerBox.Text)
if otherPlayer then
if otherPlayer == Player then print('You cant send money to yourself') return end
if PlayerData.Drachma >= amount and amount <= 5000 then
Events.SendMoney:FireServer(amount,otherPlayer)
elseif amount > 5000 then
print("Sorry, you can only donate up to 5000!")
else
print('Sorry, you do not have enough money!')
end
else
print('Sorry"'..SendMoney.PlayerBox.Text..'" Is not a valid player!')
end
else
print('Sorry, You must enter in a valid number to send! "'.. SendMoney.AmountBox.Text .."' Is not a number!")
end
end)
It already should be, as you send the amount inside the if statement. If it’s not already above 0, it wont reach the :FireServer(amount, otherPlayer) event.