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

How do I fix this team only door for my game that does not work?

Asked by 3 years ago

This door is meant to allow people within a team to go through, but nobody else.

local Debounce = false

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") and Debounce == false then
        Debounce = true
        local plr = game.Players:GetPlayerFromCharacter(hit.Parent)

        if plr.Team == game.Teams.Police then
            script.Parent.CanCollide = false
            wait(5)
            script.Parent.CanCollide = true
            Debounce = false
        end
    end
end)
0
The debounce in your script only becomes false if they are in the right team. But it should also become false even if they aren't in the right team. andarwniceguyjr 0 — 3y

2 answers

Log in to vote
3
Answered by
appxritixn 2235 Moderation Voter Community Moderator
3 years ago

Use Collision Filtering through PhysicsService. This allows certain parts to collide in a different way than other parts (ie. the parts in a player's character and a team's door)

A helpful Roblox article can be found here that deals with team doors.

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

I got this from a game that I was working on and I think this may solve your question

debounce = false

script.Parent.Touched:connect(function(hit)
    if (hit) then
        if (hit.Parent) then
            a = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
            if (a) then
                if (a.TeamColor == BrickColor.new("Really blue")) then
                    debounce = true
                    script.Parent.Transparency = 0.5
                    script.Parent.CanCollide = false
                    wait(1)

                    script.Parent.Transparency = 0
                    script.Parent.CanCollide = true             
                    debounce = false
                end
            end
        end
    end
end)

Answer this question