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

How may I make a group rank's Access a door with a clickdetector?

Asked by 4 years ago

The base of this script is to operate a door, At a group, with a certain ranks number. But the door does not work

local group = 3444858
local rank = (255 or 239 or 240 or 241 or 242 or 243 or 244 or 245 or 246 or 247 or 248 or 249 or 250 or 251 or 252 or 253 or 254)

function onClicked(player)
    if not player then return end
    if player:GetRankInGroup(group) >= rank then
    if script.Parent.Open.Value == false then
        script.Parent.Open.Value = true
        script.Parent.Transparency = 1
        script.Parent.CanCollide = false
        print('Opened')
    elseif script.Parent.Open.Value == true then
        script.Parent.Open.Value = false
        script.Parent.Transparency = 0
        script.Parent.CanCollide = true
        print('Closed')
    end
    else
        print('NOT IN GROUP!')
    end
    end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

It does work with only One ranks, But i need multiple ranks in the group.

Which as the script doesn't seem to work with multiple ranks then more then one.

1 answer

Log in to vote
0
Answered by
RAFA1608 543 Moderation Voter
4 years ago
Edited 4 years ago

you dont need to put ALL the numbers in the table. just get the lowest number and do this:

function onClicked(player)
    if not player then return end
    if player:GetRankInGroup(group) >= 239 then
    if script.Parent.Open.Value == false then

and, the correct format for a table looks like this:

local ranks = {255,254,253,252,251,250,249,248,247,246,245,244,243,242,241,240,239}

and, in case if you dont want a certain rank to not be allowed to pass the door, just do this:

function onClicked(player)
    if not player then return end
    local rank = player:GetRankInGroup(group)
    if rank >= 239 and not rank == 255  then --doesnt let rank 255 in
    if script.Parent.Open.Value == false then

in case you want to scan all the numbers in the table ranks:

local ranks = {255,254,253,252,251,250,249,248,247,246,245,244,243,242,241,240,239}
function onClicked(player)
    if not player then return end
    local rank = player:GetRankInGroup(group)
    for i,v in pairs(ranks) do --scans thru all values in table ranks, therefore I meaning index (the number being scanned) and V meaning Value, the object/string/number being scanned.
        if rank == v then
        if script.Parent.Open.Value == false then

i hope that helped :p

0
Welp, That changed everything! Thank You so much for the Assistance & Use of proper table! S0NIC_Dev 61 — 4y
Ad

Answer this question