Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

The rank door for specific rank doesn't work, is it the not game.Players.LocalPlayer?

Asked by 7 years ago

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)
0
first off all plr = game.Players.LocalPlayer, use game:getService("Players").LocalPlayer greatneil80 2647 — 7y
0
@greatneil80 You can't use :GetService() in a LocalScript it will error yougottols1 420 — 7y
0
should be :GetRankInGroup blowup999 659 — 7y
0
yes u should use :GetRankInGroup saSlol2436 716 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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.

0
Thanks Yougo! RichMan4b 0 — 7y
Ad

Answer this question