[Closed / Resolved]

local isOn = true
local player = game.Players.LocalPlayer


function on()
 isOn = true
 script.Parent.Transparency = 0
 script.Parent.CanCollide = true
end

function off()
 isOn = false
 script.Parent.Transparency = 0.8
 script.Parent.CanCollide = false
end

function onClicked()
 if player.Team == game.Teams["Emergency Response Team"] or player.Team == game.Teams["Officer"] or player.Team == game.Teams["High-Command"] then
 if isOn == true then off() else on() end
 end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

on()

The “Error” is attempt to index nil with “Team”
How can I define Team? Thanks for ur Help

1 Like

Maybe try to define Team at the top of your script with Teams = game:GetService("Teams")

Also, is this a local script or a server script?

1 Like

local script (it is a door) (30 character)

1 Like

As @DarkDanny04 said, simply define it at the top. local team = game:GetService('Teams')
But I would suggest using TeamColor.

local player = game.Players.LocalPlayer --Player

if player.TeamColor == BrickColor.new('TeamColour') then --The Team colour.
   --Code Here
end
1 Like

If it’s a local script, it has to be in a place that replicates stuff to the client. Such as starterplayerscripts. And then you will need to change script.Parent.ClickDetector to wherever the part in the workspace is.

2 Likes

local isOn = true
local player = game.Players.LocalPlayer
local team = game:GetService("Teams")

function on()
 isOn = true
 script.Parent.Door.Transparency = 0
 script.Parent.Door.CanCollide = true
end

function off()
 isOn = false
 script.Parent.Door.Transparency = 0.8
 script.Parent.Door.CanCollide = false
end

function onClicked()
 if player.TeamColor == BrickColor.new('Black') or player.TeamColor == BrickColor.new('Br. yellowish orange') or player.TeamColor == BrickColor.new('Navy blue') then
 if isOn == true then off() else on() end
 end
end

script.Parent.Butt.ClickDetector.MouseClick:connect(onClicked)

on()

That is now the script and the door (SolDoor) But if I test and set my team to Officer ( Navy Blue) and click the Button (Butt9 the door doesnt open can u pls help me? (Im not a scripter)

1 Like

You need to put the local script inside starterplayerscripts, and change the path to the clickdetector

Make sure teams that you trying to compare with current player one is exist in teams

how do you mean this? (30Char)

You would do game.Workspace.DoorSol.Butt.ClickDetector.MouseClick:Connect(function(onClicked)

local isOn = true
local player = game.Players.LocalPlayer
local team = game:GetService("Teams")

function on()
 isOn = true
 script.Parent.Door.Transparency = 0
 script.Parent.Door.CanCollide = true
end

function off()
 isOn = false
 script.Parent.Door.Transparency = 0.8
 script.Parent.Door.CanCollide = false
end

game.Workspace.DoorSol.Butt.ClickDetector.MouseClick:Connect(function(onClicked)
 if player.TeamColor == BrickColor.new('Black') or player.TeamColor == BrickColor.new('Br. yellowish orange') or player.TeamColor == BrickColor.new('Navy blue') then
 if isOn == true then off() else on() end
 end
end)

so?

game.Workspace.DoorSol.Butt.ClickDetector.MouseClick:Connect(function(player) Sorry, it should be like that, with the player as the parameter, and as long as its in starterplayerscripts it should work

and how can I change this that the door does this? (script.parent.Door doesnt go)

Since there’s more than 1 part named door you would have to use a loop.

for _, v in pairs(game.Workspace.DoorSol:GetChildren()) do
    if v.Name == "Door" then
        v.Transparency = .8
        v.CanCollide = false
    end
end
1 Like

Also

function on()
 isOn = true
 for _, v in pairs(game.Workspace.DoorSol:GetChildren()) do
    if v.Name == "Door" then
        v.Transparency = .8
        v.CanCollide = false
    end
end
end

Is this correct?

I think that would be for the off() function, but yes that would be right.

Yes it works thank you so much!

1 Like

It only works on 1 door. What can i do that it works on more than one door (not at the same time) I mean that i can open a door but i cant open an other door

robloxapp-20200729-2218004.wmv (521,0 KB)

(i can only open the original door)