I’ve got a sliding door controlled by 2 buttons; open and close. Inside we have a click detector and script.
I wish to make it so only certain users can use it. I’d prefer userid in case they change their name.
I’ve tried a lot of scripts, none work.
Any help is much appreciated.
(If you can add a groupid and group rank bit too that’d help.)
Open Script:
local Service = game:GetService("TweenService")
local Gate = script.Parent.Parent.Door2
local Info = TweenInfo.new(8)
script.Parent.ClickDetector.MouseClick:Connect(function()
script.Parent.CanCollide = false
local Change = {Position = Vector3.new(599.155, 45.715, 66.553)}
local Tween = Service:Create(Gate, Info, Change)
Tween:Play()
end)
Close Script:
local Service = game:GetService("TweenService")
local Gate = script.Parent.Parent.Door2
local Info = TweenInfo.new(8)
script.Parent.ClickDetector.MouseClick:Connect(function()
script.Parent.CanCollide = true
local Change = {Position = Vector3.new(598.885, 45.715, 62.373)}
local Tween = Service:Create(Gate, Info, Change)
Tween:Play()
end)
function check()
if game.Players.LocalPlayers.UserId == "userid here" then
return true
else
return false
end
--your open and close script inside the mouseclick event put the check() at the start of it
local Service = game:GetService("TweenService")
local Gate = script.Parent.Parent.Door2
local Allowed = {
1614394440, -- your userID
}
local Info = TweenInfo.new(8)
script.Parent.ClickDetector.MouseClick:Connect(function(hit)
for i,v in pairs(Allowed) do
if hit.UserId == v then
print("allowed")
script.Parent.CanCollide = false
local Change = {Position = Vector3.new(599.155, 45.715, 66.553)}
local Tween = Service:Create(Gate, Info, Change)
Tween:Play()
end
end
end)
I haven’t actually tested it but it should work
add in the table all user ids you want to use
If you want it to also check if he is in a group then you could do this
local Service = game:GetService("TweenService")
local Gate = script.Parent.Parent.Door2
local Group = 0 -- groupID
local Rank = 0 -- rankID
local Info = TweenInfo.new(8)
script.Parent.ClickDetector.MouseClick:Connect(function(hit)
if hit:GetRankInGroup(Group) == Rank then
print("allowed")
script.Parent.CanCollide = false
local Change = {Position = Vector3.new(599.155, 45.715, 66.553)}
local Tween = Service:Create(Gate, Info, Change)
Tween:Play()
end
end)
In addition to Sir_Numb, instead of doing for _,v in pairs you can do table.find() - Basically does the same as for _,v in pairs, but is kinda cleaner.