✓ Accepted answer
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)
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
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.
4 comments
first off all plr = game.Players.LocalPlayer, use game:getService("Players").LocalPlayer
@greatneil80 You can't use :GetService() in a LocalScript it will error
should be :GetRankInGroup
yes u should use :GetRankInGroup