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

How can I make a Team Door work correctly?

Asked by 7 years ago

Hey, I've been trying to make a door that if you pass through it and you are not a specific team, it kills you. Everything I do doesn't work and there are no models of it. If someone could please tell me how I'l be really thankful.

1 answer

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

Try this, haven't tested it though.

-- Put this in the door PART not model

local Debounce = false -- prevent opening too much

local ForTeam = BrickColor.new("Bright red") -- replace bright red with team color name
local OpenTime = 0.5 -- open time

script.Parent.Touched:connect(function(touchedpart) -- once touched
    if touchedpart.Parent:IsA("Model") then -- if it is indeed a model
        if touchedpart.Parent:FindFirstChild("Humanoid") then -- if model has humanoid
            local Player = game.Players:GetPlayerFromCharacter(touchedpart.Parent) -- attempt to get player from model
            if Player then -- if it is a player
                if Player.TeamColor ~= ForTeam then -- if player not in correct team
                    touchedpart.Parent:BreakJoints() -- kills the trespasser
                else -- if player is in team
                    if Debounce == false then
                        Debounce = true
                        local OriginalTransparency = script.Parent.Transparency
                        script.Parent.Transparency = 0.3
                        script.Parent.CanCollide = false
                        wait(OpenTime)
                        script.Parent.Transparency = OriginalTransparency
                        script.Parent.CanCollide = false
                        Debounce = false
                    end
                end
            end
        end
    end
end)
Ad

Answer this question