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

Making a specific group enter a door?

Well I wanted team "ct" enter this door. Error says their is no property "Team" in Players. (Ex. Player.Team.TeamColor)

ctdoor = script.Parent

function open()
	ctdoor.CanCollide = false
	for transparency = 0, 1, .1 do
		ctdoor.Transparency = transparency
		wait(.1)
	end
end

function close()
	for transparency = 1, 0, -.1 do
		ctdoor.Transparency = transparency
		wait(.1)
	end
	ctdoor.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

ctdoor.Touched:connect(function(part)
	local player = get_player(part)
	if not player then return end
	local allow = (
		player.Team.TeamColor == 'Really blue' --this doesn't works <<<
	)
	if allow then
		open()
		delay(4, close)
	end
end)

2 answers

Team is indeed, not a valid member or property of Player. But TeamColor is. You'd access it like so:

player.TeamColor

But you really should use the IsInGroup function.

group = 1

script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFristChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent.Humanoid)
		if player:IsInGroup(group) then
			--do stuff
		end
	end
end)

Hope this helps. I'm tired, but I want to help all that I can; please forgive any of my incoherence.

1 comment

0

I don't think "IsInGroup" helps it just does nothing. IsInGroup works for groups connected with roblox and not TeamColor

I like how MINEBLOX106 thinks but here is a better way of doing it.

local group = 1

script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') then
		if game.Players:FindFirstChild(hit.Parent.Name) then -- make sure its an actual player not a robot
			if game.Players[hit.Parent.Name]:IsInGroup(group) then
				open()
				wait(4)
				close()
			end
		end
	end
end)

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