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

How to refresh information on leaderboard/stats on respawn?

Asked by 7 years ago
local playerStats = {}

 game.Players.PlayerAdded:connect(function(player)
     local leaderstats = Instance.new("Model", player)
     leaderstats.Name = "leaderstats"

     local grouprank = Instance.new("StringValue", leaderstats)
     grouprank.Name = "Rank"
     local rank = player:GetRoleInGroup(3074970) 

     if rank ~= 0 then
         grouprank.Value = rank
     else
         grouprank.Value = "Guest"
     end

 end)

I am very new to scripting, and just learning off of free scripts I find, etc. I've been very puzzled as I want to be able the game to recheck the player's group rank when they respawn, however I just cannot figure out how to do it.

2 answers

Log in to vote
0
Answered by
ausmel105 140
7 years ago
Edited 7 years ago

The PlayerAdded event only fires when a player joins the server, not every time the player respawns.

A suitable event for what you're trying to do would be CharacterAdded, which is connected to the player. Since PlayerAdded is a good way to get the player when a new player joins the server we can combine the two to make a function which will fire every time a player respawns.

From the wiki: ChracterAdded

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        character.Humanoid.WalkSpeed = 25
    end)
end)

You can use this example with your code you have already, which looks pretty good! Just insert it below the CharacterAdded event and you should be good to go.

All the best!

0
I really appreciate the help! I tried what you suggested, however the group rank is still the same when the character is reset (obviously I did change the rank via the group). Any other ideas? :c Pyroxeme 5 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

I can help you out here. You made a couple mistakes

1) You used :GetRoleInGroup() which returns the role of the player, not the rank number. Second off, you created a model for leaderstats when you should've created an IntValue. Here's your script fixed:

local playerStats = {}

 game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(char) -- This checks to see when the character is added. When a player dies, it's character is removed and then added back. This will make any code inside of player.CharacterAdded run whenever the player resets or dies.
         local leaderstats = Instance.new("IntValue", player)
         leaderstats.Name = "leaderstats"

         local grouprank = Instance.new("StringValue", leaderstats)
         grouprank.Name = "Rank"
         local rank = player:GetRoleInGroup(3074970) 

         grouprank.Value = rank
    end)

 end)

0
I really appreciate the help! I tried what you suggested, however the group rank is still the same when the character is reset (obviously I did change the rank via the group). Any other ideas? :c Pyroxeme 5 — 7y

Answer this question