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
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)
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.
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)