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

How would I modify this script to change a leaderstat according to their rank in a specific group?

Asked by 8 years ago
function onPlayerEntered(newPlayer)
    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"

    local c = Instance.new("IntValue")
    c.Name = "Access Level"
    c.Value = 1

    c.Parent = stats

    stats.Parent = newPlayer 

    newPlayer.Changed:connect(function (property)
        if (property == "Character") then
            onPlayerRespawned(newPlayer)
        end
    end)
end

game.Players.ChildAdded:connect(onPlayerEntered)

I need this for my technology facility, where only certain ranks can enter certain areas.

1 answer

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
8 years ago

You're looking for the GetRankInGroup method!

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

    local c = Instance.new("IntValue")
    c.Name = "Access Level"

    local rank = newPlayer:GetRankInGroup(0) --Change this to the Group's ID
    if not rank or rank <= 50 then
        c.Value = 0
    elseif rank <= 100 then
        c.Value = 1
    elseif rank <= 200 then
        c.Value = 2
    else --highest ranks
        c.Value = 3
    end

    c.Parent = stats

    stats.Parent = newPlayer 

    newPlayer.Changed:connect(function (property)
        if (property == "Character") then
            onPlayerRespawned(newPlayer)
        end
    end)
end

game.Players.ChildAdded:connect(onPlayerEntered)
Ad

Answer this question