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

How do I make it so only a certain team can open a certain door?

Here's my script, it obviously isn't working

script.Parent.Touched:connect(function()
	local guard game.Players.LocalPlayer.TeamColor = BrickColor('Bright blue')
	if guard then
	script.Parent.CanCollide = false
	script.Parent.Transparency = 1
	wait(1)
	script.Parent.CanCollide = true
	script.Parent.Transparency = 0
	else
		--
	end
end)

I tried putting BrickColor.new('Bright blue') but it didn't work

Here's the error I got with this one: "attempt to call global 'BrickColor' (a table value)"

1 comment

1

One of the errors is you forgot to put a = after guard and have the end not counted as comment.

2 answers

Alright, I analyzed your script and there's lots of problems with it that are concerning me because of what you're trying to achieve.

I will just tell you what's wrong in the script and then I'll do another script which will tell you what you need to put in there or fix.

##Here's your script:

script.Parent.Touched:connect(function()
    local guard game.Players.LocalPlayer.TeamColor = BrickColor('Bright blue') -- This will not work because you set the TeamColor equal to something you're not checking for it and also, you're using LocalPlayer which will not work because this is a Server Script. Also, this line of code is completely wrong syntax-wise it just won't work. 
    if guard then -- You will have to check if the TeamColor is "Bright blue" on this line so this won't work
    script.Parent.CanCollide = false -- This should be fine if the parent's the part.
    script.Parent.Transparency = 1 -- Same for this one
    wait(1) -- Should work.
    script.Parent.CanCollide = true -- Should work.
    script.Parent.Transparency = 0 -- Should work.
    else -- Not needed but, it will work.
        -- -- Not needed.
    end -- Will work.
end) -- Will work.

##Here is the script, after I made a bit of adjustments.

script.Parent.Touched:connect(function(obj) -- The touched event has a parameter for the part that touches. It can be called whatever you want(as long as it doesn't have any spaces or, in this case I called the parameter 'obj'.
local hum = obj.Parent:findFirstChild("Humanoid") -- Searches for the Humanoid in the Character.
local player = game.Players:GetPlayerFromCharacter(obj.Parent) -- Gets the player from the character.
local teamcolor = player.TeamColor -- Variable for the property called "TeamColor" for Player.
if teamcolor == BrickColor.new("Bright blue") and hum then -- If statement checking for humanoid and if the team color is 'Bright blue'.
--Rest of your code.
end -- End for if statement.
end) -- End for function.

----EDITED----

#Well, I hope I helped in one way or another and if you have any questions please post them in the comments below.

~~ KingLoneCat

2 comments

1

I tried doing this, but I get this error : Workspace.Door1.Script:4: attempt to index local 'player' (a nil value)

0

Try it now ^ I changed a few things.

Here you go:

script.Parent.Touched:connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
local teamColorNeeded = BrickColor.new("Bright blue")
local currentColor = plr.TeamColor

if teamColor == teamColorNeeded then
	-- Code goes here
end

end)

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