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 fix this team only door for my game that does not work?

This door is meant to allow people within a team to go through, but nobody else.

local Debounce = false

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and Debounce == false then
		Debounce = true
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		
		if plr.Team == game.Teams.Police then
			script.Parent.CanCollide = false
			wait(5)
			script.Parent.CanCollide = true
			Debounce = false
		end
	end
end)

1 comment

0

The debounce in your script only becomes false if they are in the right team. But it should also become false even if they aren't in the right team.

2 answers

Use Collision Filtering through PhysicsService. This allows certain parts to collide in a different way than other parts (ie. the parts in a player's character and a team's door)

A helpful Roblox article can be found here that deals with team doors.

I got this from a game that I was working on and I think this may solve your question

debounce = false

script.Parent.Touched:connect(function(hit)
	if (hit) then
		if (hit.Parent) then
			a = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
			if (a) then
				if (a.TeamColor == BrickColor.new("Really blue")) then
					debounce = true
					script.Parent.Transparency = 0.5
					script.Parent.CanCollide = false
					wait(1)
					
					script.Parent.Transparency = 0
					script.Parent.CanCollide = true				
					debounce = false
				end
			end
		end
	end
end)

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