Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Has leaderstat script doesn't work?

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

✓ Accepted answer

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)

2 comments

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.

0

I edited your code a bit and it worked. Thank you.

This discussion is preserved as it was. New answers, comments, and votes are closed.