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

How Can I Make The Group Door Work As Intended?

Asked by
D3VRO 66
6 years ago

It works perfectly except everytime a group member passes through the door it lets a player thats not in the group pass also. I need to type a script where it only opens the door to the player who is in the group. Where do i need to do the function?

GroupId = 3366998

script.Parent.Touched:Connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr:IsInGroup(GroupId) then
        script.Parent.Transparency = 0.7
        script.Parent.CanCollide = false
        wait(2)
        script.Parent.Transparency = 0.15
        script.Parent.CanCollide = true
    end
end)

Than I did this but it still didn't work.

GroupId = 3366998
local Debounce = false;

script.Parent.Touched:Connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr and plr:IsInGroup(GroupId) and Debounce == false then
        Debounce = true;
        script.Parent.Transparency = 0.7
        script.Parent.CanCollide = false
        wait(2)
        script.Parent.Transparency = 0.15
        script.Parent.CanCollide = true
        Debounce = false;
    end
end)

1 answer

Log in to vote
0
Answered by 6 years ago

You're on the right track, all you need to do is to do something to the player if they aren't in the group. This could be teleport them away from the door or simply killing them, which is the simpler option. For now we'll make it so the player dies, but you can change it as you wish.

GroupId = 3366998

script.Parent.Touched:Connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr:IsInGroup(GroupId) then
        script.Parent.Transparency = 0.7
        script.Parent.CanCollide = false
        wait(2)
        script.Parent.Transparency = 0.15
        script.Parent.CanCollide = true
    else --If the player is not in the group then execute the code below
        local humanoid = hit.Parent:FindFirstChild("Humanoid")
        if humanoid then --Check if their humanoid exists
            humanoid.Health = 0 --If it does, then kill them.
        end
    end
end)

Problem solved! If you wanted to make the code even better now, you could leave the door >CanCollide = false as it is no longer necessary.

GroupId = 3366998

script.Parent.Touched:Connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr:IsInGroup(GroupId) then
        script.Parent.Transparency = 0.7
        wait(2)
        script.Parent.Transparency = 0.15
    else
        local humanoid = hit.Parent:FindFirstChild("Humanoid")
        if humanoid then
            humanoid.Health = 0
        end
    end
end)

et voila!

Ad

Answer this question