I am trying to make a door that only people in my group can go through. It was working yesterday but it is not working today. Can you help me solve the problem?
local Door = script.Parent
local GroupId = 5470381
game.Players.PlayerAdded:Connect(function(plr)
if plr:GetRankInGroup(GroupId) > 2 then
Door.CanCollide = false
wait (2)
Door.CanCollide = true
end
end)
I believe you’re using the wrong event. The script you have provided does the following:
When a player enters the game, and they are appropriately ranked, the door opens. When a player who doesn’t have the rank enters, the door closes. If the door was open because a ranked player joins, that ranked player will then no longer be able to walk through the door when an unranked player walks through.
I suggest taking a look at BasePart.Touched, this would work infinitely better.
Next time, do provide the scripting in a code block and provide indentation, this makes the script a lot easier for us to read and understand what is going on. Adding a code block looks like this:
```lua
code
```
ThePlayerAdded will open your door only when a player will join the game (only at the start of the game) so i dont think that is what you want. You must check when the player touches the door, then check if the player is in that group.
local groupId = 5470381
script.Parent.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
if player:IsInGroup(groupId) then
script.Parent.Transparency = 0.8
script.Parent.CanCollide = false
wait(1)
script.Parent.Transparency = 0
script.Parent.CanCollide = true
end
end
end
end)
local Door = script.Parent
local GroupId = 5470381
local debounce = false
Door.Touched:Connect(function(hit)
local plr = hit.Parent
if plr then
if debounce == false and game.Players:FindFirstChild(plr.Name):GetRankInGroup(GroupId) >= 2 then
debounce = true
Door.CanCollide = false
wait (2)
Door.CanCollide = true
debounce = false
end
end
end)
Added debounce to prevent infinite loop on door. Which will prevent some lag, if you do like it feel free to remove the denounce function.
local Door = script.Parent
local GroupId = 5470381
Door.Touched:Connect(function(plr)
if plr:GetRankInGroup(GroupId) > 2 then
Door.CanCollide = false
wait (2)
Door.CanCollide = true
end
end)
local Door = script.Parent
local GroupId = 5470381
Door.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
if plr:GetRankInGroup(GroupId) > 2 then
Door.CanCollide = false
wait(2)
Door.CanCollide = true
end
end
end)
General information: <= Less than or equal to < Less than > More than >= More than or equal to ~= Does not equal == equals
Read this ROBLOX Developer Wiki Article for more information! https://developer.roblox.com/en-us/articles/Operators
I don’t think that’s how you should do it, I think you should remove the door on the client if the player is in the group.
-- in the starterplayerscripts
local door = workspace.Door
local GROUP_ID = 5470381
local player = game.Players.LocalPlayer
if player:GetRankInGroup(GROUP_ID) >= 2 then
door:Destroy()
end
If you want security then you could make a part that encompasses the room and use it to make a Region3:
local part = ... -- hitbox
local newRegion3 = Region3.new(part.Position - part.Size / 2, part.Position + part.Size / 2)
while wait(1 / 10) do -- runs 10 times per second
local parts = workspace:GetPartsInRegion3(newRegion3)
for _, part in ipairs(parts) do
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if player:GetRankInGroup(GROUP_ID) < 2 then
player.Character:MoveTo(part.Position + part.Size / 2)
end
end
end
I honestly, wouldn’t want to trust a client, but that way was proven to work.
Shouldn’t you add a function to fire it?
Like: game.Players.PlayerAdded:Connect(function(player)
Not really, you can trust the client in this case, since even on the server the client can STILL destroy the door and can get into the room either way. It’s fine in this case, and you can consider adding the edit I did to my post for extra security.