Hello, I’ve been trying to figure out how to make a rank only group door for a specific role in one of my groups and I’ve tried so many ways and looked on yt for tutorials and they have all been failures. Here is a picture of the script I’m using. Any help or feedback on this?
Looking at it, it should work for your usecase. Where is the localscript located?
Right under the part, Was I supposed to move it to ServerScriptService?
Localscripts do not work if they are not a descendant of a player/player’s character. Moving it there will not fix the issue, I’d recommend putting it in StarterPlayer → StarterPlayerScripts
What if I just put the script into a regular script page if you know what I mean would it not work?
It would error because you can only get the LocalPlayer
from a localscript, using it in a regular script would return nil
and thus would error when using the GetRankInGroup
function. If you really want it to be a regular script, then you’d need to use the Touched Evevnt and get the player from the part that hit the door,
Though again you can just put to where I told you and it would run the localscript and thus fix your issue
Yes I will try that now, Let’s say though that this part is going to be in a model inserted into another persons game would it still work then or would I have to have them put the script in their StarterPlayerScripts?
They’d need to put it the localscript there themselves if it’s not alreayd there, along would changing the reference to the door as well
Yea, I moved it and it still does not work…
I don’t get what is wrong. Can you explain more?
Can you add a print statement to see if it’s running? If it is, can you check if the result you get from GetRankInGroup is greater than or equal to the minimum you have provided
local player = game.Players.LocalPlayer
local door = workspace.StaffDoor
local min = 150
local groupid = 11313421
if player:GetRankInGroup(groupid) >= min then
print(“Player is over min”)
door.CanCollide = false
else
door.CanCollide = true
end
Add a print statement outside of the if statement to see if the code is even running in the first place, and also print the result of player:GetRankInGroup(groupid)
, if it’s less than 150, then it’s not the code that’s wrong
From what I saw from your image, I saw that you made a minor mistake causing your script to not function, here is the same exact script but change into the correct manner (there are many ways on doing it but this is personally my own way).
local player = game.Players.LocalPlayer -- Getting the player
local door = workspace:WaitForChild("StaffDoor") -- Getting the door
local min = 150 -- Defining the group rank
local GroupId = 11313421 -- Defining the Group
if player:IsInGroup(GroupId) then -- Check if player is in group/
local rank = player:GetRankInGroup(min) -- Check if player is in proper rank/
if rank then
door.CanCollide = true -- Setting the door to open
else
door.CanCollide = false -- Setting the door to close
end
end
end
-- Anyone can freely use this script however they want too!
And now u have sparked my mind to wanna learn to script again ty very much
Yes I meant if I did it correctly it should work, The rank id for the role is “150” and that’s what I put in the script. I moved it to “ServerPlayerScript” and it still does not work.
Check what @Conspiracy_Dev said
Do I put this under “ServerPlayerScript”?
What you did won’t work, player:GetRankInGroup(min) would check for the rank the player has in the group with the id 150. Player | Roblox Creator Documentation
I think you mean local rank = player:GetRankInGroup(GroupId)
and then check if rank > min.
I don’t see how this could fix it though, because if the player is not in the group, :GetRankInGroup() returns 0. Maybe the :WaitForChild() fixes it though.
@DojiRising could you tell us if there are any errors in your output?
You need to place this into a particular door with a script in it, some parts of the script might not work but you could freely amend any of it into your satisfiction.