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

Little help with my Leader Stats code?

Asked by 8 years ago

Hello guys, I just wrote a leaderstats code and it enters IntValue into player but it isn't showing up on leaderstats. It also won't show any error...anyone can help me?

game.Players.PlayerAdded:connect(function(player)
    local stats = Instance.new('IntValue', player)
    stats.Name = 'LeaderStats'
    local cash=Instance.new('IntValue',stats)
    cash.Name = 'Cash'
    cash.Value = 0
    local rank=Instance.new('StringValue', stats)
    rank.Name='Rank'
    rank.Value='Private'
end)

2 answers

Log in to vote
1
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

The 'leaderstats' object is case sensitive and should be named with all lowercase letters. It is also advised for the object to be a folder or model as there is a chance it won't work if you use a Value object.

game.Players.PlayerAdded:connect(function(player)
    local stats = Instance.new("Folder")
    stats.Name = "leaderstats"
    stats.Parent = player

    local cash = Instance.new("IntValue")
    cash.Name = "Cash"
    cash.Value = 0
    cash.Parent = stats

    -- which ever other stats you want
end)
0
Thanks man! theepicspider1 15 — 8y
Ad
Log in to vote
0
Answered by
Sir_Melio 221 Moderation Voter
8 years ago

The object must be named leaderstats with only lowercase letters. I added the line to get the user's role from a groupid you need to enter.

game.Players.PlayerAdded:connect(function(player)
    Instance.new("Folder", player).Name = "leaderstats"
    Instance.new("NumberValue", player).Name = "Cash"
    Instance.new("StringValue", player).Name = "Rank"

    player.leaderstats.Rank.Value = player:GetRoleInGroup(0)
end)

Answer this question