Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

0

server, so you may want to implement rate-limiting on the server side as well to prevent the system from being exploited.

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.