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

Leaderboard Script Broke?

Asked by 10 years ago
game.Players.PlayerAdded:connect(function(Player)

    function Leaderstats()
        leaderstats = Instance.new("IntValue")
        leaderstats.Parent = Player
        leaderstats.Name = "leaderstats"
    end

    function PowerLevel()
        PowerLevel = Instance.new("IntValue")
        PowerLevel.Parent = Player:FindFirstChild("leaderstats")
        PowerLevel.Name = "Power Level"
    end

    function Attack()
        Attack = Instance.new("IntValue")
        Attack.Parent = Player:FindFirstChild("leaderstats")
        Attack.Name = "Attack"
        Attack.Value = 25
    end

    function Defense()
        Defense = Instance.new("IntValue")
        Defense.Parent = Player:FindFirstChild("leaderstats")
        Defense.Name = "Defense"
        Defense.Value = 25
    end

    function Agility()
        Agility = Instance.new("IntValue")
        Agility.Parent = Player:FindFirstChild("leaderstats")
        Agility.Name = "Agility"
        Agility.Value = 25
    end

    function Energy()
        Energy = Instance.new("IntValue")
        Energy.Parent = Player:FindFirstChild("leaderstats")
        Energy.Name = "Energy"
        Energy.Value = 25
    end

    function Rank()
        Rank = Instance.new("StringValue")
        Rank.Parent = Player:FindFirstChild("leaderstats")
        Rank.Name = "Rank"
        Rank.Value = ""
    end

    function SetValue()
        leaderstats = Player:FindFirstChild("leaderstats")
        PowerLevel = Player.leaderstats:FindFirstChild("PowerLevel")
        Attack = Player.leaderstats:FindFirstChild("Attack")
        Defense = Player.leaderstats:FindFirstChild("Defense")
        Agility = Player.leaderstats:FindFirstChild("Agility")
        Energy = Player.leaderstats:FindFirstChild("Energy")
        Rank = Player.leaderstats:FindFirstChild("Rank")

        PowerLevel.Value = Attack.Value + Defense.Value + Agility.Value + Energy.Value
    end

    Leaderstats()
    PowerLevel()
    Attack()
    Defense()
    Agility()
    Energy()
    Rank()  
    SetValue()

end)

The output focuses more on

    function SetValue()
        leaderstats = Player:FindFirstChild("leaderstats")
        PowerLevel = Player.leaderstats:FindFirstChild("PowerLevel")
        Attack = Player.leaderstats:FindFirstChild("Attack")
        Defense = Player.leaderstats:FindFirstChild("Defense")
        Agility = Player.leaderstats:FindFirstChild("Agility")
        Energy = Player.leaderstats:FindFirstChild("Energy")
        Rank = Player.leaderstats:FindFirstChild("Rank")

        PowerLevel.Value = Attack.Value + Defense.Value + Agility.Value + Energy.Value
    end

    Leaderstats()
    PowerLevel()
    Attack()
    Defense()
    Agility()
    Energy()
    Rank()  
    SetValue()

end)

Output:

zars15's CFrame loaded 22:16:03.684 - ServerScriptService.Leaderboard:59: attempt to index global 'PowerLevel' (a nil value) 22:16:03.685 - Stack Begin 22:16:03.686 - Script 'ServerScriptService.Leaderboard', Line 59 - global SetValue 22:16:03.687 - Script 'ServerScriptService.Leaderboard', Line 69 22:16:03.688 - Stack End 22:16:03.689 - Disconnected event because of exception 22:17:32.284 - Auto-Saving...

2 answers

Log in to vote
0
Answered by 10 years ago

I dont know if this is going to help but when you define PowerLevel as a child of Player you are finding it in game.Players.PLAYERNAME.PowerLevel and unless this is your proper intention to have it here there that is why it has a nil because it might not exist there. This is just an answer for the first problem.

0
Im finding it in game.Players.leaderstats How do I fix it? BosswalrusTheCoder 88 — 10y
0
Well did you want it to put it there or are you wanting it to be in the game.Workspace.PLAYERNAME.PowerLevel? hockey1scool 10 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

I highly suggest you do not create a function for each value. Instead, create one function for all of them. Also, I suspect that you get the PowerLevel output error because you are searching for PowerLevel before it actually comes into existence. Before I provide a code fix, may I ask whether or not the script actually inserts the values into the Player or not? (If you don't know how to check, start a Solo Server, not play solo, and then go into the Player in the players menu and check if the values are there or not.)

Answer this question