Give coin system removing coins from both players

  1. What do you want to achieve? target player receives coins. Player coins is removed.

  2. What is the issue? Player and Target player coins are both subtracted when in the script im adding target players and subtracting players

  3. What solutions have you tried so far? I tried adding debug prints and couldn’t figure it out and I tried asking people

So basically, I’m making a “Tip System” where players can give others coins with a 30% fee. The problem is both them are getting there coins removed when only 1 should and other should get more coins (neither get any coins).

Server Script
local module = {}

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local RemoteFunctions = ReplicatedStorage:WaitForChild("Functions")
local RequestTip = RemoteFunctions:WaitForChild("RequestTip")

local SecureDataSend =require(script.Parent.SecureDataCall)
local DataModule = require(script.Parent.Data)

function module.requestSent(player, targetPlayer, amountRequested)

	print(player, targetPlayer, amountRequested)
	if not player or not targetPlayer or tostring(targetPlayer) == tostring(player) then
		return false, "An error has occured in sending."
	end
	local PlayerData = DataModule.GetData(player)
	local TargetData = DataModule.GetData(targetPlayer)
	
	if not PlayerData or not TargetData then
		return false, "An error has occured in sending."
	end
	
	if PlayerData.Coins >= amountRequested then
		local coinAmount = amountRequested - math.floor(amountRequested * .3)
		if amountRequested > 10000 then
			return false, "You can only send up to 10,000 per tip."
		end
		
		local TipData = PlayerData.TipData
		
		
		if TipData.SentInLastDay >=10000 and os.time()-TipData.LastLimited < 86400 then
			return false, "Daily Limit has been Reached!"
		end
		if TipData.SentInLastDay >= 10000 and os.time()-TipData.LastLimited >=86400 then
			TipData.SentInLastDay = 0
		end
		
		TargetData.Coins += coinAmount
		PlayerData.Coins -= amountRequested
		PlayerData.TipData.SentInLastDay += amountRequested

		if TipData.SentInLastDay >= 10000 then
			TipData.LastLimited = os.time()
		end
		
		SecureDataSend.CallToMutiple({targetPlayer, player})
		
		return true, "Successfully tipped "..tostring(targetPlayer).." "..coinAmount .. " coins!"
	end
	return false, "Not enough coins to send tip."
end


return module
Client
local module = {}

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService('ReplicatedStorage')

local Events =ReplicatedStorage:WaitForChild("Remotes")

local player = Players.LocalPlayer
local PlayerGui = player:WaitForChild("PlayerGui")

local TipPlayer = PlayerGui:WaitForChild("Tip Player")
local TipUi = TipPlayer:WaitForChild("TipUI")
local Title = TipUi:WaitForChild("Title")
local MainFrame = TipUi:WaitForChild("Frame")

local SendButton = MainFrame:WaitForChild("SendButton")
local TextBox = MainFrame:WaitForChild("AmountBox")
local WarningLabel = MainFrame:WaitForChild("TextLabel")
local ErrorMessage = TipUi:WaitForChild("Error")
local SuccessMessage = TipUi:WaitForChild("Success")

local RemoteFunctions = ReplicatedStorage:WaitForChild("Functions")
local RequestTip = RemoteFunctions:WaitForChild("RequestTip")

local Tween = require(script.Parent.Parent:WaitForChild("Tween"))

local CurrentTarget = nil
local AmountEntered = 0

local function getAmount()
	return AmountEntered - math.floor(AmountEntered * .3)
end

local function isDecimal()
	return AmountEntered ~= math.floor(AmountEntered)
end

function module.Update(target_player)
	Title.Text = 'Tip '	.. tostring(target_player)
	
	CurrentTarget = target_player
	WarningLabel.Text = "⚠️ "..tostring(target_player) .. " Will only recieve ".. getAmount().. " due to random taxes  ⚠️"
	
	if AmountEntered > 0 then		
		SendButton.Text = "Send "..getAmount().. " now!"
	end
end

function module.Message(success, message)
	if not success then
		local newMsg =ErrorMessage:Clone()
		newMsg.Visible = true
		newMsg.Text = message
		newMsg.Parent = TipUi
		
		Tween(newMsg, {Position = newMsg.Position+UDim2.new(0,0,-.04,0)} ,TweenInfo.new(.2))
		task.delay(1.5, function()
			newMsg:Destroy()
		end)
	else
		local newMsg =SuccessMessage:Clone()
		newMsg.Visible = true
		newMsg.Text = message
		newMsg.Parent = TipUi

		Tween(newMsg, {Position = newMsg.Position+UDim2.new(0,0,-.04,0)} ,TweenInfo.new(.2))
		task.delay(1.5, function()
			newMsg:Destroy()
		end)
	end
end

function module.Reset()
	AmountEntered = 0
	CurrentTarget = nil
	
	TextBox.Text = ""
end

SendButton.Activated:Connect(function()
	if not CurrentTarget or AmountEntered <= 0 or isDecimal() then
		return
	end
	local Success, Server_Message = RequestTip:InvokeServer(CurrentTarget, AmountEntered)
	
	module.Message(Success, Server_Message)
end)


TextBox:GetPropertyChangedSignal("Text"):Connect(function()
	if not tonumber(TextBox.Text) or not CurrentTarget then
		return
	end
	AmountEntered = tonumber(TextBox.Text)
	module.Update(CurrentTarget)
end)

return module
GetData function (not sure if need here)
function DS_Functions.GetData(player)	
	local trys = 0
	local data = nil

	if Datas[player.UserId] then
		return Datas[player.UserId] 
	end

	while trys < MaxAttempts do
		trys +=1
		if data then break end
		local success, errormsg = pcall(function()
			data = DataStore:GetAsync(player.UserId)
		end)
		if errormsg then
			warn(errormsg)

			if errormsg == "502: API Services rejected request with error. Error code: 7 Reason: Studio access to APIs is not allowed." then	
				return nil
			end
		end

		if not data then
			if not errormsg then
				return Default_Data
			end
		end
		if data then
			for name, d in pairs(Default_Data) do
				if not data[name] then
					data[name] = d
				end
			end

			return data
		end
		task.wait(.1)
	end
end