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

I'm making a money remote event that gives a player money. It doesn't work, why?

Asked by 5 years ago

So, I have a RemoteEvent called AddMoney. I keep on getting this error: 10:01:43.603 - Value is not a valid member of Player. I don't know if I have something wrong with the ServerScript or the LocalScript, but I need to fix this. Any help?

ServerScript:

game.ReplicatedStorage.Events.AddMoney.OnServerEvent:Connect(function(player, cash)
    for _,v in pairs(game.ServerStorage.PlayerMoney:GetChildren()) do
        if v.Name == player.Name then
            v.Value = v.Value + cash.Value
        end
    end
end)

LocalScript:

local events = game:GetService("ReplicatedStorage").Events
local addImage = events.AddImage
local addMoney = events.AddMoney

local player = game.Players.LocalPlayer
local gui = player.PlayerGui.ShipmentGui.ShipmentFrame

local debounce = false
for _,v in pairs(gui.ShipmentButtons:GetChildren()) do
    if (v:IsA("TextButton")) then
        local value = v.ItemUnlocked
        if (value) then
            v.MouseButton1Click:Connect(function()
                if (value.Value == true) then
                    if (debounce == false) then
                        debounce = true
                        addMoney:FireServer(player, v.Money)

                        wait(.5)
                        gui.Visible = false

                        wait(20)
                        debounce = false
                    end
                end
            end)
        end
    end
end

If you're confused with the "PlayerMoney", that is just a value stored in the server so that it can't be hacked by any clients

0
The code has a security flaw: when firing the RemoteEvent, the client is able to set `cash` to an arbitrary value, which isn't probably what you want. You may want to consider validating the amount of money to add on the server, or creating separate events that yield fixed amounts (specified in server scripts) of cash. Also, keep in mind that the MouseButton1Click debounce doesn't affect the gskw 1046 — 5y
0
server, so you may want to implement rate-limiting on the server side as well to prevent the system from being exploited. gskw 1046 — 5y

1 answer

Log in to vote
2
Answered by
SmartNode 383 Moderation Voter
5 years ago

When your firing from the client, never put your player as an argument because ROBLOX automatically does this for you.

Ad

Answer this question