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

How to make a Click-Door for specific teams?

Hello,

I am making a prison game. Certain teams need to be able to access the door, and when they click on the door, it should open. However, only the first team (Bright blue) is allowed to open the door, and not the rest in local teams. Please help! This script is inside of a click detector.

local teams = BrickColor.new("Bright blue") or BrickColor.new("Bright red")
local open = false

script.Parent.MouseClick:Connect(function(Plr)
	print("Started")
	if Plr.TeamColor == teams then
	if open == false then
		print("Checked the team Colored")
		for i,v in pairs(script.Parent.Parent.Parent.Door:GetChildren()) do
			v.Transparency = 1
			v.CanCollide = false
			open = true
		end
	elseif open == true then
		for i,v in pairs(script.Parent.Parent.Parent.Door:GetChildren()) do
			v.Transparency = v.Transp.Value
			v.CanCollide = true
			open = false
		end
	else
		wait(30)
		for i, v in pairs(script.Parent.Parent.Parent.Door:GetChildren()) do
			v.Transparency = v.Transp.Value
			v.CanCollide = true
			open = false
	end
			end
	else
		print("Don't have passed!")
	end
end)

1 comment

0

These doors should also close after 30 seconds, but they do not.

1 answer

✓ Accepted answer

Line 1: Okay, let me set this up so you can understand. Notice what I have here:

local a = false or nil or 1 or 2
print(a); --> 1

Notice how variable a is 1 but not false or nil. This means values of false or nil will be "skipped" from the or operator. This also means that there is one value per variable, otherwise variable a would also print 2.

So based on your script variable teams can only have one value, which is BrickColor.new("Bright blue") only.

So if you want to compare one value with multiple values, one way is to get the multiple values into a table and use table.find

Here's an example:


local table_1 = {1,3,5};

if table.find(table_1,2)then
	print('Found a value in a table') -- does not print a value since no index has value 2
end;
if table.find(table_1,3)then
	print('Ok printed for real') -- printed since index 2 has the value
end;

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