Okay, so I have this game that has rank only doors and I have been using the script below for it.
local rank = 2 -- The rank
local groupID = 5206514 -- The group ID
script.Parent.Touched:connect(function(hit)
if (hit and hit.Parent and game.Players:FindFirstChild(hit.Parent.Name)) then
if (game.Players[hit.Parent.Name]:IsInGroup(groupID) and game.Players[hit.Parent.Name]:GetRankInGroup(groupID) >= rank) then
script.Parent.CanCollide = false
script.Parent.Transparency = .1
wait(1)
script.Parent.CanCollide = true
script.Parent.Transparency = 1
else
script.Parent.CanCollide = true
end
end
end)
But it causes an immense amount of lag, and can have other players glitch through. I understand this script, but I don’t get how you could make it seamless and without lag. I have seen other cafes with stuff like this. Could you help me out?
The way I use it is by deleting the doors upon player entering the server. If the player is a staff member, delete the doors (on their client only). This is a better way of doing it, so you don’t have to worry about other people gaining access when a player opens it, for example, if the door opened for 2 seconds when a staff member walked into it.
Using a LocalScript. A LocalScript is on each client, but that doesn’t mean everyone gets access through the door. You can do your checks in the LocalScript, but just make sure that it’s in a place where client scripts can function (e.g. StarterPlayerScripts would be ideal for this)
Ideally for this you’d want to use remote events, on server you would detect when someone has touched the trigger part and then proceed to check if the player meets the requirements of that door, then have the server fire the event to the client in order to open the door for them.
As for the reason behind your script causing lag, you have not included a debounce, meaning that every part that touches the trigger part will run the code.
local plr = game.Players.LocalPlayer
if plr:GetRankInGroup (5206514) >=2 then
if game.Workspace:FindFirstChild("SnackDoor") then
game.Workspace.CurrentCamera.SnackDoor:Destroy()
end
else
local door = game.Workspace:FindFirstChild("SnackDoor"):Clone()
door.Parent = game.Workspace.CurrentCamera
door.CanCollide = true
door.Anchored = true
door.CFrame = game.Workspace:FindFirstChild("SnackDoor")
end
Seem to be over complicating it just a little bit.
If the door is already there, make sure that it is by default:
Anchored
CanCollide set to true
local plr = game.Players.LocalPlayer
game.Players.PlayerAdded:Connect(function()
if plr:GetRankInGroup (5206514) >=2 then
if game.Workspace:FindFirstChild("SnackDoor") then
game.Workspace.SnackDoor:Destroy()
end
end
end)
Well not detailed, script but I think, problem is in parent.
Try this script:
GroupIdenabled = true--Enable or Disable the group and rank check feature. Set "true"
to enable and “false” to disable.
GroupId = 5206514 --Change this to GroupID of your group.
min = 2
max = 255 --Change this to the maximum Group Rank Value (Rank 0-255) a Player can enter.
--Item ID--
ItemIdenabled = false --Enable or Disable
ItemId = 0
local KilluponTouched = true
local WaitTime = 0.5
DoorTransparency = 1
Door = script.Parent
Q = false
--Makes Sure Player is Within Guidelines (Correct rank, group, possible, and/or they have the correct item within their inventory)--
--Group Check--
if GroupIdenabled == true then
function Touched(Part)
local Human = Part.Parent:findFirstChild("Humanoid")
if Q then return end
Q = true
if Part.Parent then
p=game.Players:getPlayerFromCharacter(Part.Parent)
if p then
if p:GetRankInGroup(GroupId) >= min and p:GetRankInGroup(GroupId) <= max or (CheckExceptions(Human.Parent.Name))then
AccessGranted()
else
print("Nice Try, Skrub")
if KilluponTouched then Part.Parent:breakJoints()
wait(WaitTime)
end end end end Q = false end end
--Item Check--
if ItemIdenabled == true then
function Touched(Part)
local human = Part.Parent:findFirstChild("Humanoid")
if Q then return end
Q = true
if Part.Parent then
p=game.Players:getPlayerFromCharacter(Part.Parent)
if p then
if game:getService"BadgeService":UserHasBadge(p.userId,ItemId)then
AccessGranted()
else
print("Own the Item to Gain Access")
if KilluponTouched then Part.Parent:breakJoints()
wait(WaitTime)
end end end end Q = false end end
--Opens Door If Player's Rank was Correct--
function AccessGranted()
print("Access Granted")
Door.Transparency = 1
Door.CanCollide = false
wait(WaitTime)
Door.CanCollide = true
Door.Transparency = DoorTransparency
end
Door.Touched:connect(Touched)
local plr = game:GetService("Players").LocalPlayer
if plr:GetRankInGroup(5206514) >= 2 then
if game:GetService("Workspace"):FindFirstChild("SnackDoor") then
game:GetService("Workspace").SnackDoor:Destroy()
end
end
How many of these are you using? I personally use this system (Extremely similar code) for a military base I’m helping develop. We currently have five of these doors and have so far had no problems in terms of lag. Albeit, the base is still a WIP, and only has around 1.5k parts currently.
Also, have you tried putting the script in a LocalScript? That way, even if dozens of players are entering and leaving, the lag would be drastically reduced, as multiple people hitting the same door can cause the server to run the script over and over.
Sad to see no love for Collision Filtering. This would definitely make for a seamless door. I currently use this for my group where there’s three groups per tier of a group rank (visitor, staff, high rank) and areas of the map collide with some groups and others don’t.
Ok so I made the script, it worked and then I went to sleep. Then I got up and tested it again and it is just working very oddly… Like when I first got on I could not go through, so I invited some people to test it and at the sart they could not go through, but eventually could. Then I got the owner to come on and test it and he could go through just fine.