Staff Door Scripting Issue?

Hey! I am making a hotel game, and I need a Staff Door for my hotel game. I’m not sure if the script is wrong, or there is a mistake. But here is the script:
local Player = game.Players.LocalPlayer

local doorPart = game.Workspace.Door.Door

local groupId = 10250221

local minimumRank = 4

if Player:GetRankInGroup(groupId) >= minimumRank then

print(“Player is at or above minimum rank”)

doorPart.CanCollide = false

else

print(“Player is below minimum rank”)

doorPart.CanCollide = true

end

1 Like

It’s because you never defined Player in your script.

Try this :

local doorPart = game.Workspace.Door.Door
local groupId = 10250221
local minimumRank = 4


game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(char)
		if Player:GetRankInGroup(groupId) >= minimumRank then
			print("Above Minimum")
			doorPart.CanCollide = false
		else
			print("Below Minimum")
			doorPart.CanCollide = true
		end
	end)
end)


I will try it! Thanks for the help!

1 Like

It doesn’t seem to work. {The script is in the staff door)

local doorPart = game.Workspace.Door.Door
local groupId = 10250221
local minimumRank = 4

game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(char)
if Player:GetRankInGroup(groupId) >= minimumRank then
print(“Above Minimum”)
doorPart.CanCollide = false
else
print(“Below Minimum”)
doorPart.CanCollide = true
end
end)
end)

I put exactly that.

local doorPart = game.Workspace.Door.Door
local groupId = 10250221
local minimumRank = 4


game.Players.PlayerAdded:Connect(function(Player)
	if Player:GetRankInGroup(groupId) >= minimumRank then
		print("Above Minimum")
		doorPart.CanCollide = false
	else
		print("Below Minimum")
		doorPart.CanCollide = true
	end
end)


Still doesn’t work… Sorry. I put it correctly.

Could you check your output and see what it says?

the second line you said Door.Door in some cases it can cause undetected errors

Ill show you a picture of the output when I join.

local doorPart = game.Workspace.Door.door
local groupId = 10250221
local minimumRank = 4


game.Players.PlayerAdded:Connect(function(Player)
	if Player:GetRankInGroup(groupId) >= minimumRank then
		print("Above Minimum")
		doorPart.CanCollide = false
	else
		print("Below Minimum")
		doorPart.CanCollide = true
	end
end)

Change one of the ‘Door’ children to something else, that’s the only issue I can detect here.

Doesnt work… #################

Put this as a LocalScript putting it as a serverscript will break

local Player = game:GetService("Players").LocalPlayer
local config = {
  ['MinimumRank'] = 1234,
  ['GroupId'] = 1234,
  ['Door'] = path.to.door
}

if Player:GetRankInGroup(config.GroupId) >= config.MinimumRank then
  door.CanCollide = false
else
  door.CanCollide = true
end

is the script a local script or a server script, if the script is a local script it wont even run since it has to be in the player or the players character, if it is a server script it will run but it will also open the door for everyone in the server and LocalPlayer does not work for server scripts

local doorPart = game.Workspace.Door.Door --define door here

doorPart.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		
		
		if player:GetRankInGroup(10250221) >= 4 then
			doorPart.CanCollide = false
		else
			doorPart.CanCollide = true
		end
	end
end)

What you are trying to do is when a player joins, the ‘CanCollide’ will be off or on whether the player is lower or above than the rank. When trying to do it with the touched event, the ‘CanCollide’ will changed depends on the player rank upon touching.

The script itself should work, make sure the script is a local script and try placing it in the StarterPack. Also you might want to change game.Workspace.Door.Door to

workspace:WaitForChild("Door"):WaitForChild("Door")

I recommend creating a folder named “Doors,” or any other name that you prefer, and inserting the doors inside the folder you created. The folder must be placed inside of workspace, of course. After that, you can insert a simple local script inside of StarterPlayerScripts, and it’ll manage all of the doors on the client, as that’s what I assume you want to do(?) hence the calling of LocalPlayer.

With this, you won’t be using the Touched event either. This way is smoother and won’t give players that slight delay if you know what I mean.

local config = {
	['GroupID'] = 1,
	['GroupRank'] = 11,
	['FolderPath'] = workspace.Doors
}

local players = game:GetService("Players")
local client = players.LocalPlayer

if (client:GetRankInGroup(config.GroupID) >= config.GroupRank) then
	for index, door in pairs(config.FolderPath:GetChildren()) do
		door.CanCollide = false
	end
end

Images if you need more help:

Your script worked the first time I tried it and it still works, but it stops working from time to time.

I did that. It works but it doesnt work from time to time.

What I get when the door doesnt work:

16:00:17.371 Requiring asset 563619835.
Callstack:
Workspace.Basic Admin Essentials 2.0.Basic Admin Essentials 2.0, line 371

  • Server - Basic Admin Essentials 2.0:371
    16:00:17.371 Requiring asset 3239236979.
    Callstack:
    Workspace.HD Admin.Settings.Loader, line 12
  • Server - Loader:12
    16:00:17.371 ServerScriptService.OverHead:10: Expected function call arguments after ‘(’ - Studio - OverHead:10
    16:00:19.725 Door is not a valid member of Model “Workspace.Door” - Client - GroupRankDoorScript:1
    16:00:19.725 Stack Begin - Studio
    16:00:19.725 Script ‘Players.thebossbear13.Backpack.GroupRankDoorScript’, Line 1 - Studio - GroupRankDoorScript:1
    16:00:19.725 Stack End - Studio
    16:00:20.042 TestService: Basic Admin Essentials 2.0 | 5.5.10.20.649P.0 | Prefix: “” | Act. Prefix: “!” - Studio
    16:00:20.042 TestService: Basic Admin Essentials 2.0 | DP: true | CD: true - Studio

What I get when it works:

16:01:47.580 ServerScriptService.OverHead:10: Expected function call arguments after ‘(’ - Studio - OverHead:10
16:01:47.581 Requiring asset 563619835.
Callstack:
Workspace.Basic Admin Essentials 2.0.Basic Admin Essentials 2.0, line 371

  • Server - Basic Admin Essentials 2.0:371
    16:01:47.581 Requiring asset 3239236979.
    Callstack:
    Workspace.HD Admin.Settings.Loader, line 12
  • Server - Loader:12
    16:01:49.105 TestService: Basic Admin Essentials 2.0 | 5.5.10.20.649P.0 | Prefix: “” | Act. Prefix: “!” - Studio
    16:01:49.105 TestService: Basic Admin Essentials 2.0 | DP: true | CD: true - Studio

There you go. Hopefully you can fix it.