Server Script => ServerScriptService
local Event = game.ReplicatedStorage:FindFirstChild("AddMoney") or Instance.new("RemoteEvent",game.ReplicatedStorage
Event.Name = "AddMoney"
Event.OnServerEvent:connect(function(Player)
local PlayerMoney = game.ServerStorage.GoldStorage:FindFirstChild(Player.Name)
if PlayerMoney then
PlayerMoney.Value = PlayerMoney.Value + 500
end
Local Script => In Button
local Event = game.ReplicatedStorage:WaitForChild("AddMoney")
script.Parent.MouseButton1Down:connect(function()
Event:FireServer()
end
There could be multiple reasons why your script did not work. First, your original script should have been a Local script.
If your script was a local script: Your script could not access "ServerStorage" because only the server may access it.
If your script was not a local script, your script would not even detect that the button was clicked.
Local Script goes in Button.
Server Script goes in ServerScriptService
P.S.: FilteringEnabled Supported.
2 comments
Bad suggestion. Use RemoteEvents instead.
My goal was to identify his problems (that 0_0 didn't already cover) and supply simple and feasible solutions, not to re-write all his code. Coding yourself will always help you learn more than having someone do all the work for you. Even still, in this situation remotes would likely decrease efficiency.