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

2 comments
The code has a security flaw: when firing the RemoteEvent, the client is able to set
cashto 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 theserver, so you may want to implement rate-limiting on the server side as well to prevent the system from being exploited.