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

Leaderstats not showing up?

Asked by
Trewier 146
10 years ago

My leaderstats script doesnt seem to work. I've changed it several times, but no matter what I do, it won't work. If anyone can help me here it is:

local nshow = {"attack","strength","defense","fishing","smithing","fletching","cooking",
"woodcutting","crafting","theiving","prayer","farming"} --Different non-showing skills

--Load Data
game.Players.PlayerAdded:connect(function(player)
    player:WaitForDataReady()
    --Leaderstats
    leaderstats.Parent = game.Players:FindFirstChild(player)
    leaderstats.Name = "leaderstats"
    Level = Instance.new("IntValue")
    Level.Parent = leaderstats
    Gold = Instance.new("IntValue")
    Gold.Parent = leaderstats
    Skill = Instance.new("IntValue")
    Skill.Parent = leaderstats

    Gold.Name = "Gold"  
    Level.Name = "Gold"
    Skill.Name = "Skill"

    if not pcall(function() Skill.Value = player:LoadNumber("Skill") end) then
    Skill.Value = 0
    end
    if not pcall(function() Gold.Value = player:LoadNumber("Gold") end) then
    Gold.Value = 0
    end
    if not pcall(function() Level.Value = player:LoadNumber("Level") end) then
    Level.Value = 1
    end


    --stats
    local stats = Instance.new("Configuration", player)
    stats.Name = "stats"
    for _, stat in pairs(nshow) do
        stata = Instance.new("IntConstrainedValue", stats)
        stata.Name = stat
        stata.MinValue = 1
        stata.MaxValue = 99
        if not pcall(function() stata.Value = player:LoadNumber(stat.Name) end) then
        stata.Value = 0
        end
        Instance.new("IntValue",stata).Name = "xp"
        if not pcall(function() stat.Value = player:LoadNumber(stat.Name.."xp") end) then
        stat.Value = 0
        end
        Instance.new("IntValue",stata).Name = "nxp"


    end
end)

--Save Data
game.Players.PlayerRemoving:connect(function(player)
    player:WaitForDataReady()

    for i,e in pairs(nshow) do
        player:SaveNumber(e.Name,player.stats:FindFirstChild(e).Value)      
        player:SaveNumber(e.Name.."xp",player.stats:FindFirstChild(e).xp.Value)
    end

    player:SaveNumber("Skill",Skill.Value)
    player:SaveNumber("Gold",Gold.Value)
    player:SaveNumber("Level",Level.Value)
end)
0
Can you be more specific on what isn't working? User#2 0 — 10y
0
I really can't. I have run it several times but it does not error, and it doesn't give the leaderstats to the player. Sorry I can't give more info. Trewier 146 — 10y
0
Are you only testing this in play solo? In solo, the player is made before playeradded fires. User#2 0 — 10y
0
Perhaps through some print lines here and there, to see how far it goes until it crashes? AmericanStripes 610 — 10y
View all comments (2 more)
0
I am testing in server. I'll try the print thing later. a little busy right now... Trewier 146 — 10y
1
You never defined "leaderstats" Thewsomeguy 448 — 10y

1 answer

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago
    player:WaitForDataReady()
    --Leaderstats
    leaderstats = Instance.new("IntValue", player)
    leaderstats.Name = "leaderstats"

Instance's 'new' method takes a second parameters, which is what you want to set the parent of what you just created to.

Also, 'player' points to the actual Player object; it isn't a string value.

Ad

Answer this question