This is my leaderstat script inside of serverscript service
local function onPlayerJoin(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local gold = Instance.new("IntValue") gold.Name = "Gold" gold.Value = 0 gold.Parent = leaderstats end game.Players.PlayerAdded:Connect(onPlayerJoin)
How do i get +1 gold when i press my button inside of gui
So put this in a localscript with the buttons path being where the button is. Local script should be in starterGui, playercharacterscripts or playerscripts
local player = game.Players.LocalPlayer local remoteEventName = game.ReplicatedStorage.RemoteEventName buttonspath.MouseButton1Click:Connectfunction() remoteEventName:FireServer() end)
Server Script: (Should be in serverscriptservice)
local remoteEventName = game.ReplicatedStorage.RemoteEventName remoteEventName.OnServerEvent:Connect(function(player) player.leaderstats.gold.value = player.leaderstats.gold.Value + 1 end)
Create a remote event and place in replicated storage.
You need to fire to the server to change the value because if the client did it then the server would never know.