I've been trying to get this to work, I'm not sure what I'm doing wrong and it won't let the the rank higher to go through.
local plr = game.Players.LocalPlayer script.Parent.Touched:Connect(function() if plr:GetRoleInGroup(3346930) >= 5 then script.Parent.CanCollide = false wait(1) script.Parent.CanCollide = true else plr:LoadCharacter() end end)
Problem:
First of all make sure to indent your code so it easier to read. Second what you are doing is comparing a String
to a Number Value
. The method :GetRoleInGroup()
is a method that returns a String
of what Role
the player is in the group with. If the player is not in the group then it returns the player as a "Guest".
Solution:
Since you are looking for a specific Rank
to get in through the Door you need the method :GetRankInGroup()
. This will return a number to be able to compare. It is also best if you use Server Script for this issue. Which also means to use the method :GetPlayerFromCharacter()
.
Code:
ServerScript
Since we are starting off with a ServerScript
the LocalPlayer
will not work out with your first variable.
So here I added the :GetPlayerFromCharacter()
script.Parent.Touched:Connect(function(hit) local plr = game.Players:GetPlayerFromCharacter(hit.Parent) --In the parenthesis you hold the value of what you are referencing to, the model) It is basically getting the player from the character if you didn't know what this method was end)
Next we add the fixed :GetRankInGroup()
method
script.Parent.Touched:Connect(function(hit) local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if plr:GetRankInGroup(3346930) >= 5 then --Here we are comparing two numbers instead of a string and number end end)
Lastly we have all the other stuff you wanted in the script, so here is the finished code
script.Parent.Touched:Connect(function(hit) local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if plr:GetRankInGroup(3346930) >= 5 then script.Parent.CanCollide = false wait(1) script.Parent.CanCollide = true else plr:LoadCharacter() end end)
If you have any questions don't be afraid to comment, I would be glad to help. If this helped you then don't forget to accept my answer.