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

Has leaderstat script doesn't work?

Asked by 7 years ago

Hello guys, I'm hoping that you can help me here. I've been trying to figure out what is wrong with this script but I cannot find anything. It is supposed to check if my Rank does not have enough permissions to open the door it's supposed to kill the player but instead it kills me no matter what my Rank is. Please see code below if I didn't make sense here. Any help appreciated.

Scanning = false

function Scan(hit)
if Scanning == false then
Scanning = true



if hit.Parent:FindFirstChild("Humanoid") then

local Player = game.Players[hit.Parent.Name]


if Player:WaitForChild('leaderstats').Rank.Value == 'Hotel Guest' or 'Suspended' or 'Noted Guest' or 'Trainee' or 'Receptionist' or 'Senior Receptionist' then

print("\\ACCESS RESTRICTED\\ ~~ "..Player.Name)

local Gui = game.ServerStorage.AccessDenied:Clone()
Gui.Parent = Player.PlayerGui

Player.Character.Humanoid.WalkSpeed = 0
wait(1)
Player.Character.Humanoid.Health = 0

wait(2)

Scanning = false

else

Scanning = false
end

else

Scanning = false
end


else

end
end
script.Parent.Touched:connect(Scan)

2 answers

Log in to vote
1
Answered by
Azarth 3141 Moderation Voter Community Moderator
7 years ago
Edited 7 years ago

You'd have to write if Player:WaitForChild('leaderstats').Rank.Value == 'Hotel Guest' for every name. You can't say or and then the name; that translates to is "Suspended" true or is "HotelGuest" true, which doesn't mean anything to the script as that's just a string.

local Scanning = false


-- A dictionary type of table will help keep 
-- you ordered when you have a lot of things to check against.
local RestrictedRanks = {

    ['Hotel Guest'] = true;
    ['Suspended'] = true;
    ['Noted Guest'] = true;
    ['Trainee'] = true;
    ['Receptionist'] = true;
    ['Senior Receptionist'] = true

}

function Scan(hit)
    if Scanning == false then
        Scanning = true
        if hit and hit.Parent then 
            local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
            if Player then 
                local hum = Player.Character:findFirstChild("Humanoid")
                if not hum then return end
                local leaderstats = Player:WaitForChild("leaderstats")
                if leaderstats then 
                    local rank = leaderstats.Rank
                    if RestrictedRanks[rank.Value] then -- Search for rank in table                 
                        print("\\ACCESS RESTRICTED\\ ~~ "..Player.Name)

                        local Gui = game.ServerStorage.AccessDenied:Clone()
                        Gui.Parent = Player.PlayerGui

                        hum.WalkSpeed = 0
                        wait(1)
                        hum.Health = 0
                        wait(2)
                        Scanning = false
                    else
                        Scanning = false
                    end
                else
                    Scanning = false
                end
            end
        end
    end
end

script.Parent.Touched:connect(Scan)

0
Thank you Azarth for trying to help me. Your answer did not work and nothing is showing up in the output. I appreciate your willingness to help anyway. TheEpicCooldeal 12 — 7y
0
I edited your code a bit and it worked. Thank you. TheEpicCooldeal 12 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

Try using :GetRankInGroup

Answer this question