So in my game is roleplay based on a group. what i have been looking for is a group door that only people from an especific team, espefic rank on especific group can go throught it
I tried looking so far, nothing i could get helped with, i’m a noob on this of developing. so far this is what i have, the script somewhat works, but its very laggy and the rank id from the group doesn’t work.
local rank = 34 -- the rank the player will need to get through (out of 255)
local groupID = 0 -- The group ID the player must be in
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 = .9
wait(1)
script.Parent.CanCollide = true
script.Parent.Transparency = 0
else
script.Parent.CanCollide = true
end
end
end)
It’s laggy because you require to put a debounce before the door can be attempted to be opened again, Also, I think the rank part isn’t working because you didn’t specify a groupId, you kept it as 0
local rank = 34 -- the rank the player will need to get through (out of 255)
local groupID = 0 -- The group ID the player must be in
local deb = false
script.Parent.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent) -- Returns the player if hit.Parent is a player character, else nil
if plr then
if plr:IsInGroup(groupID) and plr:GetRankInGroup(groupID) >= rank and not deb then
deb = true
script.Parent.CanCollide = false
script.Parent.Transparency = .9
wait(1)
script.Parent.CanCollide = true
script.Parent.Transparency = 0
deb = false
else
script.Parent.CanCollide = true
end
end
end)
Also use :Connect instead of :connect since the latter is deprecated
Also, do you think if its possible if someone is on a certain team cannot go through that door, like if some “good people” can go thru it but “bad people” cannot? like “Civilian” and “Criminals” cannot go throught that door even if they are in the group?
There’s a method for that called GetRoleInGroup, which returns the name of the role the player has i nthe specified group or “Guest” if they are not in the group. You can include that in many ways, I usually would use a table to store the not allowed roles
Something like this
local rank = 34 -- the rank the player will need to get through (out of 255)
local groupID = 0 -- The group ID the player must be in
local excludedRoles = {"Criminal","Civilian"} -- Add more
local deb = false
script.Parent.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
if plr:IsInGroup(groupID) and plr:GetRankInGroup(groupID) >= rank and not table.find(excludedRoles, plr:GetRoleInGroup(groupID)) then
if not deb then
deb = true
script.Parent.CanCollide = false
script.Parent.Transparency = .9
wait(1)
script.Parent.CanCollide = true
script.Parent.Transparency = 0
deb = false
end
else
script.Parent.CanCollide = true
end
end
end)
_Tha’s really useful! thanks, but i think i didn’t clarify it well. from what i was talking about like “civilians”,“criminals” were Teams, not so they aren’t allowed in.roles in groups, but its also useful because some role in my group is “exilied”
Ohh, I see. That’s easy too, there’s a property in the player called Team, it gets the current team that the player is in, so to get the name you’d do plr.Team.Name and use it to check through the table
local rank = 34 -- the rank the player will need to get through (out of 255)
local groupID = 0 -- The group ID the player must be in
local excludedRoles = {"Criminal","Civilian"} -- Add more
local deb = false
script.Parent.Touched:connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
if plr:IsInGroup(groupID) and plr:GetRankInGroup(groupID) >= rank and (plr.Team and not table.find(excludedRoles, plr.Team.Name)) then
if and not deb then
deb = true
script.Parent.CanCollide = false
script.Parent.Transparency = .9
wait(1)
script.Parent.CanCollide = true
script.Parent.Transparency = 0
deb = false
end
else
script.Parent.CanCollide = true
end
end
end)
Fixed an issue with the code regarding the Taem property since if a player is not in a team, it returns nil
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local Criminals = Teams.Criminals
local Police = Teams.Police
local door = game.Workspace.Door -- put your door here
door.Touched:Connect(function(hit)
if hit then
local PlayerChar = Players:GetPlayerFromCharacter(hit.Parent)
if PlayerChar and PlayerChar.Team == Police then
door.Transparency = 0.3
door.CanCollide = false
wait(3)
door.Transparency = 0
door.CanCollide = true
end
elseif PlayerChar and PlayerChar.Team == Criminals then
PlayerChar:BreakJoints()
end
end
That code would only do half of what @xfixfixfixfixfixfi wanted (Team detection and Group Detection) and there’s a bit of errors such as you writing Criminals as Crimanls and the Event is not closed so it would error, and a lack of an elseif. You should’ve looked at your code carefully before replying
Anytime! I would recommend setting one of my posts as the solution as to help anyone else who may have a similar issue like you had! If you have any more questions or issues don’t be afraid to make another post!
I know that this is really off topic, but when I create a topic, The name is grayed out on the list. When I posted in #help-and-feedback no one replied and it is all greyed out. I has been 2 hours now.
You just really need to put the names of the teams you want to exclude in a table like how I did with excludedRoles, any names in that table that match a team will not be allowed through