Hello, there! I am currently working on a door that would open when clicked by a player with a certain rank in my group. However, I am having some troubles as my doors consist of multiple parts which causes issues.
My current script:
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local hinge = script.Parent.Doorframe.Hinge
local click_detector = script.Parent.Base.ClickDetector
local goal_open = {}
goal_open.CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(90), 0)
local goal_close = {}
goal_close.CFrame = hinge.CFrame * CFrame.Angles(0, 0, 0)
local tween_info = TweenInfo.new(1)
local tween_open = TweenService:Create(hinge, tween_info, goal_open)
local tween_close = TweenService:Create(hinge, tween_info, goal_close)
local open = false
local group = 34215674
local rank = 200
click_detector.MouseClick:Connect(function(player)
if Players:GetPlayerFromCharacter(player.Character) then
local player_real = Players:GetPlayerFromCharacter(player.Character)
if player_real:GetRankInGroup(group) >= rank then
if open then
open = false
tween_close:Play()
else
open = true
tween_open:Play()
end
else
player.Character:MoveTo(Vector3.new(script.Parent.NoPermissions.Position))
end
end
end)
script.Parent.Detector.Touched:Connect(function(hit, player)
if not hit.Parent:FindFirstChildOfClass("Humanoid") then return end
if Players:GetPlayerFromCharacter(hit.Parent) then
local player_real = Players:GetPlayerFromCharacter(hit.Parent)
if player_real:GetRankInGroup(group) >= rank then
return
else
hit.Parent:MoveTo(Vector3.new(script.Parent.NoPermissions.Position))
end
end
end)```