Greetings,
I have some problems with my money sending system. I am not sure why does it do it, but it should send the money to the specified person, but for some reason, it sends it to the same person. Here are my scripts:
1st being a local script
script.Parent.MouseButton1Click:Connect(function(player)
local player = game.Players.LocalPlayer
print(player.Name.. " is the sender")
local sender = player.Name
local cash = player:WaitForChild("leaderstats"):WaitForChild("Cash")
local receiver = script.Parent.Parent.Player.Text
local amount = script.Parent.Parent.Amount.Text
local amountvalue = script.Parent.Amount.Value
amountvalue = amount
local rs = game:GetService("ReplicatedStorage")
local re = rs:WaitForChild("Sending"):WaitForChild("Send")
local percent = amountvalue / 20
local finalamount = amount - percent
if game.Players:FindFirstChild(receiver) then
print("Amount is: " ..amountvalue)
print("Final amount is: " ..finalamount)
print("Receiver is: " ..receiver)
re:FireServer(amount, receiver, sender, finalamount, cash, amountvalue)
print("Remote event for sending has been triggered.")
elseif not game.Players:FindFirstChild(receiver) then
print("Receiver " ..receiver.. " not found.")
end
end)
2nd being a server script located in serverscriptservice
local rs = game:GetService("ReplicatedStorage")
local re = rs:WaitForChild("Sending"):WaitForChild("Send")
local players = game:GetService("Players")
re.OnServerEvent:Connect(function(localPlayer, sender, amount, receiver, finalamount, cash, amountvalue)
print("Remote event for sending has been received.")
print(sender, amountvalue, receiver, finalamount)
localPlayer:WaitForChild("leaderstats"):WaitForChild("Cash").Value = localPlayer:WaitForChild("leaderstats"):WaitForChild("Cash").Value - amountvalue
players:WaitForChild(receiver):WaitForChild("leaderstats"):WaitForChild("Cash").Value = players:WaitForChild(receiver):WaitForChild("leaderstats"):WaitForChild("Cash").Value + finalamount
print("Transaction completed.")
end)
I used a remote event to connect the 2 scripts. The problem seems to occur in the second script at the following line players:WaitForChild(receiver):WaitForChild("leaderstats"):WaitForChild("Cash").Value = players:WaitForChild(receiver):WaitForChild("leaderstats"):WaitForChild("Cash").Value + finalamount
Please help me, I don’t understand where I may be wrong. Thanks!