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
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
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
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