Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
mikwbm 9
3 years ago

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

0
Hey accept my friends req let’s go into a studio M9F 94 — 3y

1 answer

Log in to vote
2
Answered by 3 years ago
Edited 3 years ago

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.

0
so on the local script i did everything u said and it has red line under the end) and it says expected <eof>, got 'end' idk what to do mikwbm 9 — 3y
1
That means it’s missing an end somewhere in your code. Or there’s an extra end. Recheck your code to make sure. SethHeinzman 284 — 3y
Ad

Answer this question