My door that I have made in Roblox Studio allows anyone to go through it, how would I allow only specific group ranks to enter it? Just to be clear, I would like multiple group ranks to enter it. I will put the script below as the door has an animation to it and I intend to keep it.
local TweenService = game:GetService("TweenService")
local DoorPart = script.Parent
local OpenDoor = TweenService:Create(DoorPart, TweenInfo.new(2), {Position = Vector3.new(33.181, 4.034, -156.476)})
local CloseDoor = TweenService:Create(DoorPart, TweenInfo.new(2), {Position = Vector3.new(41.019, 4.034, -156.476)})
local CD = false
DoorPart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(âHumanoidâ) and CD == false then
CD = true
OpenDoor:Play()
wait(3)
CloseDoor:Play()
wait(3)
CD = false
end
end)
There are two ways that you can do this, using roles or ranks. I prefer using ranks, as it is universal to name changes in the roles, but that is my preference.
First, you would need to get the player of the character that touched the door. This can be done as such:
local player = Players:GetPlayerFromCharacter(hit.Parent)
Second, you need to verify they are the rank or the role that you want. For example, if you only want the owner of the group and one rank below him to be allowed through, you would use the 255 and 254 Ranks. This can be done as such:
local rank = player:GetRankInGroup(yourGroupID)
local allowedRanks = {255, 254}
if table.find(allowedRanks, rank) then
Putting this all together, your new script would work as such:
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local DoorPart = script.Parent
local allowedRanks = {255, 254}
local OpenDoor = TweenService:Create(DoorPart, TweenInfo.new(2), {Position = Vector3.new(33.181, 4.034, -156.476)})
local CloseDoor = TweenService:Create(DoorPart, TweenInfo.new(2), {Position = Vector3.new(41.019, 4.034, -156.476)})
local CD = false
DoorPart.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if hit.Parent:FindFirstChild(âHumanoidâ) and CD == false then
local rank = player:GetRankInGroup(yourGroupID)
if table.find(allowedRanks, rank) then
CD = true
OpenDoor:Play()
wait(3)
CloseDoor:Play()
wait(3)
CD = false
end
end
end)
I said in my post that the first two code blocks were explaining the parts individually, and the final code block was putting them both together. You donât need to add the code from the first two code blocks to the final code block.