Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Donation script keeps adding cash to myself?

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

1 answer

Put that script in a TextButton and use function onButtonClicked, so try again.

2 comments

0

It's a RemoteEvent

0

Wrong. Bad for filtering enabled.

This discussion is preserved as it was. New answers, comments, and votes are closed.