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

How do you allow people through Door restrictions?

I tried different codes GetChildren, GetPlayers, IsInGroup, game.Players.LocalPlayers and it just wouldn't allow anyone to go through the door. I just want TeamColor "Really Blue" also known as Team "ct" to get through the door

local leaderboard = script.Parent.Parent:WaitForChild('leaderboard')
local door = script.Parent

function open()
	door.CanCollide = false 
	for transparency = 0, 1, .1 do
		door.Transparency = transparency
		wait(.1)
	end
end
 
function close()
	for transparency = 1, 0, -.1 do
		door.Transparency = transparency
		wait(.1)
	end
	door.CanCollide = true
end
 

function get_player(part)
	for _, player in ipairs(game.Players:GetPlayers()) do
		if part:IsDescendantOf(player.Character) then
			return player
		end
	end
end
 
 
door.Touched:connect(function(part)
	local player = get_player(part)
	if not player then return end
 
	local allow = (
		game.Players:GetChildren().TeamColor == 'Really blue' --THIS LINE IS KILLING ME
	)
	if allow then
		open()
		delay(4, close)
	elseif not allow then
		game.Players.LocalPlayer:LoadCharacter()
	end
end)

Oh and if you are going to reply don't reply to me about "IsInGroup".

1 comment

0

Also it just loads the character... No errors found

1 answer

✓ Accepted answer

This is what's wrong:

game.Players:GetChildren().TeamColor == 'Really blue'

It is wrong because:

1. You did not specify which child of game.Players:GetChildren() to index.

2. Team Color values are not strings, they are BrickColor.new("Color name")

This is a different, simpler version of your function, less fancy, but just as effective:

door.Touched:connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		if player.TeamColor == BrickColor.new("Really blue") then
			open()
			delay(4,close)
		end
	end
end)

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