Rank Door Part 2

Ok so I made a post similar to this that you can see here
But my issue is that it doesn’t work that well. So no matter what lower ranks can never get in so that is good. But either it takes like 15 minutes for it to recognize you have a rank higher than 2, lets you in right away, or it just doesn’t let you in at all. Here is the local script below that is located in StarterPlayerScripts

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)

Please respond with answering these three questions.
What is causing this?
How can I fix this?
Is there a more efficient way to do this?

Put it in the server script service.

game:GetService("Players").PlayerAdded:Connect(function(plr)
    if plr:GetRankInGroup(5206514) >= 2 then
        if workspace.SnackDoor then
            workspace.SnackDoor:Destroy()
        end
    end
end)

This is a bit more optimal, the global variable “workspace” is faster, GetService is faster than direct indexing Players.

2 Likes

Would that work? I am trying to do this client sided not serversided.

Oh, no. It won’t work because it’s not a server script. I’d recommend that you use @NeoInversion 's method instead.

This is alright, but, make it touchable, like

game.Workspace.SnackDoor.Touched:Connect(function(hit)
--stuff
end)
local Player = game.Players.LocalPlayer

if Player:GetRankInGroup (5206514) >= 2 then
    game.workspace.SnackDoor:Destroy()
end

Local script

1 Like

Well, that would not work for three reasons. I want it client sided, I want it to be that a certain rank in a group can go through, and I am wanting it to be smooth and not lag.

1 Like

You could tag every “snackdoor” using collectionservice:AddTag()
You could also use nocollisionconstraints to make it so the player who has the correct rank just doesn’t collide with the snackdoor, this is a serversided way to do it which is probably the best way that shouldn’t lag.

2 Likes

Try using CanCollide instead of using “Destroy()”
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.CanCollide = false
else
game.Workspace.SnackDoor.CanCollide = true
end
end
end)
“Don’t tested yet!”

I don’t understand why you’re checking when a child is added to the Players service. I would personally make a group door like this (in StarterPlayerScripts):

local p = game:GetService("Players").LocalPlayer

if p:GetRankInGroup(5206514) >= 2 then
	game:GetService("Workspace"):WaitForChild("SnackDoor"):Destroy()
end

So we have Kohls Admin in that game and I think it is interfereing with the door. Because if we give someone admin they can go through, and if we take it away they can’t which is really weird, because once you destroy the door, it is gone right?

1 Like

The door may have other scripts that allow that to happen. Look for anything that might be allowing Kohl’s to have a relationship with the door.

Also, since you want it on the client:

local plr = game:GetService("Players").LocalPlayer
if plr:GetRankInGroup(5206514) >= 2 then
    if workspace.SnackDoor then
        workspace.SnackDoor:Destroy()
   end
end

Should work just fine, and of course, being on the client will delete solely for the client.