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

My leaderstats don't show up. How do I fix this?

Asked by 4 years ago

So, I'm trying to make leaderstats. I've followed a lot of tutorials, this is what i have.

function onPlayerEntered(newPlayer)
    wait(.5)
    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"

    local score = Instance.new("IntValue")

    score.Name = "Money"
    score.Value = 0

    score.Parent = stats    
    stats.Parent = newPlayer
end

game.Players.ChildAdded:connect(onPlayerEntered)

It doesn't work. How do I make one that works?

1 answer

Log in to vote
0
Answered by
XJ5M 15
4 years ago

This script also will save the currency of your cash, you also have to place this script in the ServerScriptService

local ds = game:GetService("DataStoreService"):GetDataStore("--Cash01")

game.Players.PlayerAdded:Connect(function(player)
    local folder = Instance.new("Folder",player)
    folder.Name = "leaderstats"
    local cash = Instance.new("IntValue",folder)
    cash.Name = "Cash"
    cash.Value = 20

    local key = "cash-"..player.userId

    local save = ds:GetAsync(key)
    if save then
        cash.Value = save
    end
    cash.Changed:Connect(function()
        ds:SetAsync(key,cash.Value)
    end)    
end)
Ad

Answer this question