Code to open a door on group rank isn't working

This code makes it so a door opens on group rank greater than or equal to 4.

	Door = script.Parent
	Kill = true --if you want them to die if there in the group set it to true otherwise to false
	 
	Deb = false
	script.Parent.Touched:connect(function(p)
	if p.Parent:FindFirstChild("Humanoid") then
	player = game.Players:GetPlayerFromCharacter(p.Parent)
	if player then
	if not Deb then
	Deb = true
	if Player:GetRankInGroup(5785499) >=4 then
	Door.Transparency = 0.5
	Door.CanCollide = false
	wait(0.2)
	Door.Transparency = 0
	Door.CanCollide = true
	Deb = false
	end
	elseif not Player:GetRankInGroup(5785499) <=4 then
	if Kill then
	p.Parent.Humanoid.Health = 0
	Deb = false
	end
	end
	end
	end
	end)
1 Like

Some errors I found: you named your variable “player” but then attempted to refer to “Player:GetRankInGroup()”, it should’ve been “player:GetRankInGroup()”, either that or you could’ve changed the original variable. I also changed the “elseif not Player:GetRankInGroup(x) <=4” to simply “elseif Player:GetRankInGroup(x) <=4 then” which is what I am certain you were trying to do. Finally, you had tried to add an elseif statement, but had already closed off the conditional structure.

Basically I: renamed variables so that they are consistent within the entire code, adjusted some conditional statements, and rearranged where conditional structures should’ve been closed off.

This should work for you, I have tested it :slight_smile:

    local Door = script.Parent
	local Kill = true --if you want them to die if there in the group set it to true otherwise to false
	local Deb = false
	
	script.Parent.Touched:connect(function(p)
		if p.Parent:FindFirstChild("Humanoid") then
		local Player = game.Players:GetPlayerFromCharacter(p.Parent)
			if Player then
				if not Deb then
				Deb = true
						if Player:GetRankInGroup(5785499) >=4 then
							Door.Transparency = 0.5
							Door.CanCollide = false
							wait(0.2)
							Door.Transparency = 0
							Door.CanCollide = true
							Deb = false
						elseif Player:GetRankInGroup(5785499) <= 4 then
							if Kill then
							p.Parent.Humanoid.Health = 0
							Deb = false
							end
						end
				end
			end
		end	
	end)
2 Likes

Thank you very much! I will test this in my game tomorrow morning.

SLEEP IS FOR THE WEAK NON DEVELOPERS
I tried this, and it works, thank you! :happy4:

3 Likes