Hello everyone! I am scripting a system were to go into the door you need a rank in a group. I am not sure how to do this but is it not to do with a event. If someone could help that would be great (the script below is the door system so far).
game.Players.PlayerAdded:Connect(function(player) print("Player is ranked as '" .. player:GetRoleInGroup(2) .. "' in group, 'LOL'!") end)
game.Players.PlayerAdded:Connect(function(newPlayer) if newPlayer:IsInGroup(7) then print "Player is in the Roblox Fan club!" end end)
=But on them how would you choose the role you want them to need to use the door?? This is just selecting what role they have and if they are in the group.
If you go on your group and go to the roles tab, you can see that each role has a rank assigned to it (0 the lowest, and 255 the highest). You can check if a player meets a rank requirement for the door to open. As an example:
local function onTouch(objectTouched)
local player = game.Players:GetPlayerFromCharacter(objectTouched.Parent)
if player and player:GetRankInGroup( --[[ Your group ID goes here ]]) == 255 then
--This checks if the player touching the part is the owner of the group
--If the player is the owner, the code below runs
Brick.Transparency = 0.5
Brick.CanCollide = false
wait(1.5)
Brick.Transparency = 1
Brick.CanCollide = false
end
end
What is I wanted to add more then one role?
The function returns as a integer. This means that by creating a range with
</>/==/~=
you are able to select from a variety of your group’s roles. :GetRankInGroup()
doesn’t so much compare “Roles” as it does “Ranks” relating to those roles.
Ok, you need to do a touched event on the door.
Door.Touched:Connect(function(hit) -- hit is the object that touched the door
local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- Gets the player that touched the door
if player then -- checks if a player touched the door
local Role = player:GetRoleInGroup(YourGroupID) -- Gets the players rank in group
if Role == "Customer" or "OtherRoleNotAllowed" or "OtherRolesNotAllowed" then -- Replace the other roles with other roles in your group not allowed to enter the door.
player.Character:BreakJoints() -- Kills the player if they aren't supposed to enter.
end
end
end)
Of course this is not as good as using :GetRankInGroup() but if you don’t understand how that works then you can use this. Lemme try explaining it to you in an easy to understand way. All roles in a group have a number. People who aren’t in a group have a value of 0. A player who is in the group might have a value of 5 when using this function. Chefs and other ranks will have higher values when using this function. So if you do:
Door.Touched:Connect(function(hit) -- hit is the object that touched the door
local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- Gets the player that touched the door
if player then -- checks if a player touched the door
local Rank = player:GetRankInGroup(YourGroupID) -- Gets the players rank NUMBER VALUE
if Rank < 50 then -- You can check a ranks value in the group in the group settings. Replace 50 with the number value of the lowest possible rank that is allowed to enter this door.
player.Character:BreakJoints() -- Kills the player if they aren't supposed to enter.
end
end
end)
This method means you don’t have to do:
if Role == "Customer" or "OtherRoleNotAllowed" or "OtherRolesNotAllowed" or "Role" or Guest" then
-- Uses a ton of 'or' in this if statement.
Hope this helped!