Removing a player's leaderstats if they click a gui on roblox

2k views Asked by At

Some simple code

script.Parent.MouseButton1Up:connect(function()
    ????.leaderstats.lvl.Value = 0
    ????.leaderstats.xp.Value = 0
    ????.leaderstats.gold.Value = 0

It's not even working. So the player clicks the gui, but how can it reset the players leaderstats, specifically lvl, xp, and gold, I run a fairly popular roblox rpg game with about 400 people right now and this would be an immense help.

2

There are 2 answers

0
Benjamin Taillon On

You could put the following code in a LocalScript inside your button.

    Player = game.Players.LocalPlayer --Only works inside a localscript, replace with the line below it if you need it as a Script.
    -- Player=script.Parent while (not Player:IsA("Player")) do Player = Player.Parent end

    script.Parent.MouseButton1Up:connect(function()
        local index, stat
        for index, stat in pairs(Player.leaderstats:GetChildren()) do
            stat.Value = 0
        end
    end)
0
TinFellow On

It should be in a LocalScript, so you can just use the LocalPlayer variable to get the leaderstats and set them.