Group rank kill part

I want to make an part that only one group rank can touch or otherwise you will die,but i just know how like to make a door and i don’t want it to disappear,but i don’t want collisions and i want the rank part because i can only do the group one this is what i’m using
print(“Group and rank locked and loaded”)

local Door = script.Parent

function onTouched(hit)

print(“Door Hit”)

local human = hit.Parent:findFirstChild(“Humanoid”)

if (human ~= nil ) then

print(“Touchy touchy”)

if game.Players[human.Parent.Name]:IsInGroup(5080878) == true then

print(“Not ded”)

Door.Transparency = 1.0

Door.CanCollide = True

wait(4)

Door.CanCollide = true

Door.Transparency = 0

else human.Health= 0

end

end

end

script.Parent.Touched:connect(onTouched)

1 Like
local allowGroupId = 5080878 -- add the group id that you want to allow here.

local door = script.Parent -- make this the part you want to kill the player if they're not in the above group

local preventReEntry = {}
door.Touched:Connect(function(hit)
	local humanoid, player = hit.Parent:FindFirstChildOfClass("Humanoid") or false, game.Players:GetPlayerFromCharacter(hit.Parent) or false
	if humanoid and player and not preventReEntry[player] then
		preventReEntry[player] = humanoid
		-- the part touching the door is a player
		if not player:IsInGroup(allowGroupId) then
			-- player is not in the whitelisted group
			humanoid.Health = 0 -- kill the player
		end
		delay(2,function()
			preventReEntry[player] = nil
		end)
	end 
end)

thanks but what abount the rank?


local door = script.Parent -- make this the part you want to kill the player if they're not in the above group

local preventReEntry = {}
door.Touched:Connect(function(hit)
	local humanoid, player = hit.Parent:FindFirstChildOfClass("Humanoid") or false, game.Players:GetPlayerFromCharacter(hit.Parent) or false
	if humanoid and player and not preventReEntry[player] then
		preventReEntry[player] = humanoid
		-- the part touching the door is a player
		if not player:IsInGroup(allowGroupId) then
			-- player is not in the whitelisted group
			humanoid.Health = 0 -- kill the player
		end
		delay(2,function()
			preventReEntry[player] = nil
		end)
	end 
end)```

allowGroupId  is the GroupRank part of the script.

You wanna put code inside code blocks, like this

image

print('hello world')

Now, what you’re asking is a bit weirdly worded but based on what you posted you want the door to just not collide and let the player pass through?
If so, then this is what it should be like.

local Door = script.Parent
local Players = game:GetService('Players')
local Allowed_Rank = 2
function onTouched(hit)
	print('Door Hit')
	
	local human = hit.Parent:findFirstChild('Humanoid')
	
	if human then
		print('Was a humanoid found')
		local Player = Players:GetPlayerFromCharacter(human.Parent)
		if Player and Player:GetRankInGroup(5080878) >= Allowed_Rank then
			print('twas a player that is allowed!')
			Door.CanCollide = false
			Door.Transparency = 1
			wait(3)
			Door.CanCollide = true
			Door.Transparency = 0
		else
			print('Player is not allowed')
			human:TakeDamage(100)
		end
	end

end

script.Parent.Touched:connect(onTouched)

If you wanted a specific rank and above to only be allowed through the door, here’s a modified version of my script.

local allowGroupId = 5080878 -- add the group id that you want to allow here.
local allowRank = 1 -- this rank and above can enter the door

local door = script.Parent -- make this the part you want to kill the player if they're not in the above group

local preventReEntry = {}
door.Touched:Connect(function(hit)
	local humanoid, player = hit.Parent:FindFirstChildOfClass("Humanoid") or false, game.Players:GetPlayerFromCharacter(hit.Parent) or false
	if humanoid and player and not preventReEntry[player] then
		preventReEntry[player] = humanoid
		-- the part touching the door is a player
		if not (player:GetRankInGroup(allowGroupId) >= allowRank) then
			-- player is not in the whitelisted group
			humanoid.Health = 0 -- kill the player
		end
		delay(2,function()
			preventReEntry[player] = nil
		end)
	end 
end)

At the moment your script isn’t checking if a specific group rank can open the door. The way you do this is by firing the player:GetRankInGroup(group) event. Here is a sample code of how to fix your current code below:

local group = 123 -- The group id
local groupRanks = {245,255} -- The group ranks that are allowed to open the door
local door = script.Parent


local function checkRank(groupRank) -- Checks if the players rank can open the door
	for i,v in pairs(groupRanks) do
		if v == groupRank then
			return true
		end
	end
end


local function onTouched(hit) -- Fired when the brick is touched
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		local rank = player:GetRankInGroup(group)
		if checkRank(rank) then
			door.Transparency = 1
			door.CanCollide = false
			wait(4)
			door.Transparency = 0
			door.CanCollide = true
		else
			hit.Parent.Humanoid.Health = 0 -- Kills the player if they can't open the door
		end
	end
end

script.Parent.Touched:Connect(onTouched)