Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Send money GUI does not change values on server side. Any idea?

Asked by 3 years ago

Player money values stores at ServerStorage.PlayerMoney folder with player names inside.

I tried both remote event and function. Both prints true values to output but changes not effects server side values.

This is local script

script.Parent.MouseButton1Click:Connect(function()
    local receiver = script.Parent.Parent._02receiverplayer.Text
    local amaount = script.Parent.Parent._03amaount.Text
    game.ReplicatedStorage.sendmoney:InvokeServer(receiver,amaount)
end)

This is script inside ServerScriptService

game.ReplicatedStorage.sendmoney.OnServerInvoke = function(player, receiver, amaount)
    local receiverCheck = game.ServerStorage.PlayerMoney:FindFirstChild(receiver)
    if receiverCheck == nil then
        print("Receiver name invalid")
    elseif player.Name == receiver then
        print("You cant send money to yourself")
    else
        local totalplayermoney = game.ServerStorage.PlayerMoney[player.Name].Value
        print(player.Name.." "..totalplayermoney) --prints correct values
        local receiversmoney = game.ServerStorage.PlayerMoney[receiver].Value
        print(receiver.." "..receiversmoney) --prints correct values
        if totalplayermoney > amaount then
            totalplayermoney = totalplayermoney - amaount
            receiversmoney = receiversmoney + amaount
            print("transfer made")
            print(player.Name.." new sender money = "..totalplayermoney) --prints correct values
            print(receiver.." new receiver money = "..receiversmoney) --prints correct values
        end
    end

end

Thanks for your help.

0
You should use RemoteEvents, not remote functions Leamir 3138 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

i removed if statements from server script and i didnt use variables and it works now. i dont know why.

new server script:

game:GetService("ServerScriptService")

game.ReplicatedStorage.sendmoney.OnServerInvoke = function(player, receiver, amaount)

game.ServerStorage.PlayerMoney[player.Name].Value = game.ServerStorage.PlayerMoney[player.Name].Value - amaount

game.ServerStorage.PlayerMoney[receiver].Value = game.ServerStorage.PlayerMoney[receiver].Value + amaount

end

Ad

Answer this question