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

What is wrong with this group only door script?

Asked by 9 years ago

I am attempting to script a door that lets only ranks above 20 in that group through.

ID=2606952
Part=script.Parent

script.Parent.Touched:connect(onTouched)
function onTouched(hit)
    if Part.Parent:FindFirstChild("Humanoid") then
    local Player=game.Players:GetPlayerFromCharacter(Part.Parent)
    if Player:IsInGroup(ID) then 
        if Player:GroupRank(20) then
        script.Parent.CanCollide=false
        wait(0.1)
        script.Parent.CanCollide=true
    end
end
end
end

It won't let through the rank 20. Also for letting every rank above 20 through what do I do? Do I have to list every rank above 20? Or can I tell it to allow every rank value above 20?

My original is terrible, but with help from drew1017 and KoreanBBQ I got this -

ID=2606952
part=script.Parent
rank=player:GetRankInGroup(ID)

part.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        player=game.Players.GetPlayerFromCharacter(hit.Parent)
        if rank > 19 then
        part.CanCollide=false
        wait(1)
        part.CanCollide=true
    end
end
end)

but neither of theirs or this one works. What am I doing wrong? e.e

2 answers

Log in to vote
0
Answered by
KoreanBBQ 301 Moderation Voter
9 years ago

Erm, your arguments and all are kind of weird. Try this:

local ID=2606952
local part=script.Parent

part.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local plr=game.Players.GetPlayerFromCharacter(hit.Parent)
        if plr:RankInGroup(ID)>19 then
        part.CanCollide=false
        wait(0.1)
        part.CanCollide=true
    end
end)

Please upvote if it works ;)

0
Thank you so much, but when I touched the Part nothing happened... e.e Brisingr360 45 — 9y
0
Maybe change the CanCollide time to like 10 seconds and change the transparency to make it noticable. KoreanBBQ 301 — 9y
0
I did change the wait time and made it change the transparency to 0.5 and back to 0, but nothing happens when I touch the brick. Is the script not firing, maybe? I know I am definitely in the group and far above rank 20. Brisingr360 45 — 9y
Ad
Log in to vote
0
Answered by
drew1017 330 Moderation Voter
9 years ago

2 things: 1. GroupRank is not a method or property; In order to get what rank a player is you have to use GetRankInGroup(id of group) method on Player.

  1. You are using Part.Parent to find out what touched the Part, but this doesn't refer to the part that touched the door, it refers to script.Parent. If you need to refer to the part that touched the door, use hit (or whatever was put in the arguments of the Touched function, in this case hit).

Something like this:

ID=2606952
Part=script.Parent

script.Parent.Touched:connect(onTouched)
function onTouched(hit)
if hit.Parent:FindFirstChild("Humanoid") then
    local Player=game.Players:GetPlayerFromCharacter(hit.Parent)
    if Player:IsInGroup(ID) then 
        rank = Player:GetRankInGroup(ID)
        if rank >= 20 then
        script.Parent.CanCollide=false
        wait(0.1)
        script.Parent.CanCollide=true
    end
end
end
end

(P.S. you dont have to use spaces for indenting, just use tab to indent)

0
Thanks so much, but I tried your script and when I touched the Part nothing happened. Brisingr360 45 — 9y
0
Are you testing this in Studio while you're logged in? drew1017 330 — 9y

Answer this question