Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Detail garage team door. Where is it/I going wrong?

Line 6 is where I thought it will work but it's not. If you remove player.TeamColor == BrickColor.new("Institutional white") and then it works, but I am trying to make a team door. It's a multiple part garage door. Half was solved already (Garage door part) but the team door part wasn't solved.

local MainPart = script.Parent
local Model = MainPart.Parent.Door
player = game.Players
	
function toggleVisibility(bool)
    if  player.TeamColor == BrickColor.new("Institutional white") and bool == false then
        for i,v in pairs(Model:GetChildren()) do
            v.Transparency = 1
			v.CanCollide = false
        end
    wait (2)
        for i,v in pairs(Model:GetChildren()) do
            v.Transparency = 0
			v.CanCollide = true
			script.Parent.Parent.Door.Part7.Transparency = 0.4
        end
    end
end

function onTouched(touched)
    toggleVisibility(false)
    wait(2)
    toggleVisiblilty(true)
end

MainPart.Touched:Connect(onTouched)

2 comments

0

game.Players is a service. 'player' (game.Players) is not a player, but a service.. so saying 'player.TeamColor' makes no sense because TeamColor is not a valid member of game.Players.

0

True,

1 answer

✓ Accepted answer

You put player as game.Players which is a list of players, you need to specify a player. You will need to get the player who touched, below there will be a script that will do that.

local MainPart = script.Parent
local Model = MainPart.Parent.Door

function toggleVisibility(bool, touched)
    local player = game.Players:GetPlayerFromCharacter(touched.Parent) --Gets player from character, touched.Parent is the player character.
    if  player.TeamColor == BrickColor.new("Institutional white") and bool == false then
        for i,v in pairs(Model:GetChildren()) do
            v.Transparency = 1
            v.CanCollide = false
        end
    wait (2)
        for i,v in pairs(Model:GetChildren()) do
            v.Transparency = 0
            v.CanCollide = true
            script.Parent.Parent.Door.Part7.Transparency = 0.4
        end
    end
end

function onTouched(touched) --Touched is the part that touched the door.
	if touched.Parent:FindFirstChild("Humanoid") then --Checks if the touched part is a player.
		toggleVisibility(false, touched)
		wait(2)
		toggleVisiblilty(true, touched)
	end
end

MainPart.Touched:Connect(onTouched)

Replace your script with the one above, this should work. Comment if you have any questions or if it doesn't work.

This discussion is preserved as it was. New answers, comments, and votes are closed.