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

This Door for people in my group won't work on touch why?

Asked by 8 years ago
Edited 8 years ago

This is a Touched:connect(function() script that when you touch it and you are in my group the part goes canCollide = false

This works when there is no group statement but with the group statement it doesn't work..

Why ? Also i would like to add the is a certain Rank as well for it to work.. but i do not know how to at all

group = 2627973 -- this is the group they need to be in
rank = 4 -- this is the rank they need to be in the group

script.Parent.Touched:connect(function(h)
    if h.Parent.Humanoid ~= nil and h.Parent:IsInGroup(group) then
        script.Parent.CanCollide = false
    end
end)

2 answers

Log in to vote
2
Answered by 8 years ago
Edited 8 years ago

The problem is that IsInGroup is a function of Player, however you are calling it on the player's character, which is a Model. To fix this, use the GetPlayerFromCharacter function:

group = 2627973 -- this is the group they need to be in
rank = 4 -- this is the rank they need to be in the group

script.Parent.Touched:connect(function(h)
    local player = game.Players:GetPlayerFromCharacter(h.Parent)
    if player and player:GetRankInGroup(group) >= rank then
        script.Parent.CanCollide = false
    end
end)

To only allow certain ranks, use the GetRankInGroup function.

Additionally, you may wish to have the door close again after a specified time.

Ad
Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

I had a problem like this before, try this:

group = 2627973 -- this is the group they need to be in
rank = 4 -- this is the rank they need to be in the group

script.Parent.Touched:connect(function(h)
    if h.Parent.Humanoid ~= nil and h.Parent:IsInGroup(group) >= rank then
        script.Parent.CanCollide = false
    end
end)

I did this because even though your not in the group, your rank in the group is 0 (Guest Rank).

Answer this question