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

Im trying to add +1 gold to my leaderstat when i click a button on gui?

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

1 comment

0

Hey accept my friends req let’s go into a studio

1 answer

✓ Accepted answer

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.

2 comments

0

so on the local script i did everything u said and it has red line under the end) and it says expected , got 'end' idk what to do

1

That means it’s missing an end somewhere in your code. Or there’s an extra end. Recheck your code to make sure.

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