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

How do I make a tool where you gain a leaderstat?

Asked by 5 years ago

Honestly, I have no clue how

1 answer

Log in to vote
0
Answered by 5 years ago

I don't know what the use of this would be, but you just create a leaderstats value under the player when a tool is equipped

Let's say you have a tool called sword in StarterPack, the following LocalScript would add leaderstats to the player if put inside of the tool:

local Player = game.Players.LocalPlayer -- Local Player
local Tool = script.Parent -- Tool

Tool.Equipped:connect(function() -- Equipped event for tool
    local LeaderStats = Instance.new("IntValue", Player) -- Inserts a value called leaderstats into the player
    LeaderStats.Name = "leaderstats"
    local SecondsHeld = Instance.new("IntValue", LeaderStats) -- Creates a value called seconds held inside of leaderstats
    SecondsHeld.Name = "seconds held" 

    coroutine.resume(coroutine.create(function() -- starts a new thread
        while wait(1) do -- every second seconds held goes up by 1
            SecondsHeld.Value = SecondsHeld.Value+1
        end
    end))
end)

I'm not sure if creating a leaderstats from the client replicates to the server, so I would not use this script without RemoteEvents or RemoteFunctions.

0
:) thanks SharkOwen_dev 69 — 5y
Ad

Answer this question