I want to donate someone 1 percent of my current cash. However, the script constantly adds cash to myself.
Events.Donate.OnServerEvent:connect(function(player, option)
--ERROR CODE BELOW--
local data = player.PlayerData
local players = game:GetService("Players")
local increment = 0.01 --1% of their money
--local donationValue = data.Cash.Value - (data.Cash.Value * 0.01)
--print(donationValue)
local recipient = tostring(option)
local function updateDonationValue()
donationValue = (data.Cash.Value * 0.01)
end
--Individual player
if game.Players:FindFirstChild(recipient) then
updateDonationValue()
data.Cash.Value = data.Cash.Value - (donationValue)
print(donationValue)
players[recipient].PlayerData.Cash.Value = players[recipient].PlayerData.Cash.Value + donationValue
end

2 comments
It's a RemoteEvent
Wrong. Bad for filtering enabled.