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 this a team thing instead of a player?

How do I make it so a team can get through not just a player?

door = script.Parent;
locked = true

function setform(v)
locked = v
if v then
door.Transparency = 1
door.Reflectance = 0.4
door.CanCollide = true
else
door.Transparency = 0.7
door.Reflectance = 0
door.CanCollide = false
end

end


function click(player)
if player.Name == "Username" then
if locked then
setform(false)
wait(5)
setform(true)
end
end
end

door.ClickDetector.MouseClick:connect(click)

1 comment

0

please indent you code, and players have a Team property

2 answers

✓ Accepted answer

In order to determine that a player is a valid member of a Team, you can use the Team property of the player (which returns a team) and check its name against a string.

You do not require the setform function to be separate from the door's clickdetector.

You can also use a debounce (I switched the variable "locked" into one) to prevent players from spamming the clickdetector so that the door stays open or glitches.

Revised Server Script

door = script.Parent
locked = true

door.ClickDetector.MouseClick:Connect(function(player)
	if locked == false then return end
	locked = false
	if player.Team.Name == "TeamNameHere" then
		door.Transparency = 0.7
		door.Reflectance = 0
		door.CanCollide = false
		wait(5)
		door.Transparency = 1
		door.Reflectance = 0.4
		door.CanCollide = true
	end
	locked = true
end)

2 comments

0

I'm sorry, what's going on with line 7 there?

0

player.Team itself is a string, so you don't need to do player.Team.Name

replace if player.Name == "Username" then with

local player = game.Players:FindFirstChild(player.Name)
if player.Team == "Team"

2 comments

0

The mouse click event returns a player object, you don't need to check if it is a member of players

0

Oh. I tought it returned the player in the workspace.

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