How would I ONLY allow a FEW teams to use a proximity prompt?

Hey there friend, I made a post about allowing a specific team able to open a door, yet now I switched to ProximityPrompts. I tried using the same code for one team, it worked, yet I want MORE TEAMS. So I used the code from last time yet instead of one team, I have a variable with about 7 teams listed. I have my team service, player service, and get player variables to see if the player is on that team, yet it doesn’t work.

So my goal basically is to get a fully functional door only to specific teams, yet anyone on a team other…the door will do nothing.

My issue is plain and simple, the code/door just breaks…nothing works.

So far, I have this for the variable and team service.

local plr = game:GetService("Players").LocalPlayer
local Teams = game:GetService("Teams")

local teamsallowed = {
	"Specialized Medical Department",
	"Research Division",
	"Assistant Authoritor",
	"Manufacturer",
	"Deputy Authoritor"
}

Here is the full source code:

local Hinge = script.Parent.Hinge
local opened = false

local Promt1 = script.Parent.Parent.Keycard1.Union.ProximityPrompt
local Promt2 = script.Parent.Parent.Keycard2.Union.ProximityPrompt

local plr = game:GetService("Players").LocalPlayer
local Teams = game:GetService("Teams")

local teamsallowed = {
	"Specialized Medical Department",
	"Research Division",
	"Assistant Authoritor",
	"Manufacturer",
	"Deputy Authoritor"
}

function OpenDoor1()
	if opened == false and plr.Team == Teams[teamsallowed] then
		opened = true
		Promt1.ActionText = "Close"
		script.Parent.SoundPart.Granted:Play()
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0, math.rad(5), 0))
			wait()
		end
	else
		opened = false
		Promt1.ActionText = "Open"
		script.Parent.SoundPart.Granted:Play()
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0, math.rad(-5), 0))
			wait()
		end
	end
end
Promt1.Triggered:Connect(function(Players)
	OpenDoor1()
end)

function OpenDoor2()
	if opened == false and plr.Team == Teams[teamsallowed] then
		opened = true
		Promt2.ActionText = "Close"
		script.Parent.SoundPart.Granted:Play()
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0, math.rad(5), 0))
			wait()
		end
	else
		opened = false
		Promt2.ActionText = "Open"
		script.Parent.SoundPart.Granted:Play()
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0, math.rad(-5), 0))
			wait()
		end
	end
end
Promt2.Triggered:Connect(function(Players)
	OpenDoor2()
end)

I don’t know how to do this, so any help is appreaciated!

-lcey

3 Likes

Player.Team references the team Instance the player is in. This is why it will never be equal to a string name, therefore nobody can open it. To fix this, add a “.Name” when referencing the player’s team to check if it is authorized.

1 Like

Alright, anywhere it said plr.Team, I switched to plr.Team.Name, yet I got an error, and it didn’t work.

Traceback:

Workspace.Door.Scripted Components.DoorScript:19: attempt to index nil with 'Team'

Why are you using localplayer? I’m guessing this is ran by a script on the server and not a localscript, which is why the error says its attempting to index nil, there is no localplayer.

The “Players” parameter that you defined in the event (Which is the actual player who uses the door) goes completely unused, when thats the object you should use for the OpenDoor2() function.

local Hinge = script.Parent.Hinge
local opened = false

local Promt1 = script.Parent.Parent.Keycard1.Union.ProximityPrompt
local Promt2 = script.Parent.Parent.Keycard2.Union.ProximityPrompt

--local plr = game:GetService("Players").LocalPlayer --remove this line
local Teams = game:GetService("Teams")

local teamsallowed = {
	"Specialized Medical Department",
	"Research Division",
	"Assistant Authoritor",
	"Manufacturer",
	"Deputy Authoritor"
}

function OpenDoor1(plr) --added plr argument
	if opened == false and plr.Team == Teams[teamsallowed] then
		opened = true
		Promt1.ActionText = "Close"
		script.Parent.SoundPart.Granted:Play()
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0, math.rad(5), 0))
			wait()
		end
	else
		opened = false
		Promt1.ActionText = "Open"
		script.Parent.SoundPart.Granted:Play()
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0, math.rad(-5), 0))
			wait()
		end
	end
end
Promt1.Triggered:Connect(function(player) --renamed this to player
	OpenDoor1(player)
end)

function OpenDoor2(plr) --Added plr argument
	if opened == false and plr.Team == Teams[teamsallowed] then
		opened = true
		Promt2.ActionText = "Close"
		script.Parent.SoundPart.Granted:Play()
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0, math.rad(5), 0))
			wait()
		end
	else
		opened = false
		Promt2.ActionText = "Open"
		script.Parent.SoundPart.Granted:Play()
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0, math.rad(-5), 0))
			wait()
		end
	end
end
Promt2.Triggered:Connect(function(player) --renamed this to player
	OpenDoor2(player)
end)

Heres your code with the fixes I mentioned

2 Likes
local teams = game:GetService("Teams")
local team = teams.Team --Example team.

local prompt = script.Parent

prompt.Triggered:Connect(function(player)
	if player.Team ~= team then return end
	--Code here is executed when the player is in the required team.
end)

Here’s an example script of how you can restrict ProximityPrompts to particular teams.

2 Likes

I used this exact code, and on one of the allowed teams, I got an error…and it didn’t work.

Traceback:
Workspace.Icey's Stuff.Fake Keycard Door.Scripted Components.DoorScript:42: invalid argument #2 (string expected, got table)

Thanks! If all goes to fail with Arbi’s code, I will revert to yours, thank you!

local Hinge = script.Parent.Hinge
local opened = false

local Promt1 = script.Parent.Parent.Keycard1.Union.ProximityPrompt
local Promt2 = script.Parent.Parent.Keycard2.Union.ProximityPrompt

local Teams = game:GetService("Teams")

local teamsallowed = {
	"Specialized Medical Department",
	"Research Division",
	"Assistant Authoritor",
	"Manufacturer",
	"Deputy Authoritor"
}

function OpenDoor1(Player)
	if opened == false and table.find(teamsallowed, tostring(Player.Team)) then
		opened = true
		Promt1.ActionText = "Close"
		script.Parent.SoundPart.Granted:Play()
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0, math.rad(5), 0))
			wait()
		end
	else
		opened = false
		Promt1.ActionText = "Open"
		script.Parent.SoundPart.Granted:Play()
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0, math.rad(-5), 0))
			wait()
		end
	end
end

Promt1.Triggered:Connect(function(Player)
	OpenDoor1(Player)
end)

function OpenDoor2(Player)
	if opened == false and table.find(teamsallowed, tostring(Player.Team)) then
		opened = true
		Promt2.ActionText = "Close"
		script.Parent.SoundPart.Granted:Play()
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0, math.rad(5), 0))
			wait()
		end
	else
		opened = false
		Promt2.ActionText = "Open"
		script.Parent.SoundPart.Granted:Play()
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0, math.rad(-5), 0))
			wait()
		end
	end
end

Promt2.Triggered:Connect(function(Player)
	OpenDoor2(Player)
end)

table.find is an all together better solution. Instead of doing checks on all the whitelisted teams, you can simply just find the team you’d like with table.find!

2 Likes

This actually broke it further, the door now just swings. Like when you trigger the proximity prompt, it doesn’t go back to closed, it just keeps opening basically going in a circle.

That’s impossible, it’s the same script, but modified to use table.find, which just checks the table.

Possibly try changing all the 4 player variables to different names, that might be the problem. Otherwise, something else is going on with CFrame.

1 Like

The CFrame is alright, I just checked. Yet it seems something you must’ve added has broken the code, there is no traceback…so I don’t know what’s going on.

I don’t know what to say. The code should be working as before, except better. Here’s a modified bit:

local Hinge = script.Parent.Hinge
local opened = false

local Promt1 = script.Parent.Parent.Keycard1.Union.ProximityPrompt
local Promt2 = script.Parent.Parent.Keycard2.Union.ProximityPrompt

local Teams = game:GetService("Teams")

local teamsallowed = {
	"Specialized Medical Department",
	"Research Division",
	"Assistant Authoritor",
	"Manufacturer",
	"Deputy Authoritor"
}

function OpenDoor1(Player)
	if opened == false and table.find(teamsallowed, tostring(Player.Team)) then
		opened = true
		Promt1.ActionText = "Close"
		script.Parent.SoundPart.Granted:Play()
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0, math.rad(5), 0))
			wait()
		end
	else
		opened = false
		Promt1.ActionText = "Open"
		script.Parent.SoundPart.Granted:Play()
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0, math.rad(-5), 0))
			task.wait()
		end
	end
end

Promt1.Triggered:Connect(function(pla)
	OpenDoor1(pla)
end)

function OpenDoor2(player)
	if opened == false and table.find(teamsallowed, tostring(Player.Team)) then
		opened = true
		Promt2.ActionText = "Close"
		script.Parent.SoundPart.Granted:Play()
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0, math.rad(5), 0))
			wait()
		end
	else
		opened = false
		Promt2.ActionText = "Open"
		script.Parent.SoundPart.Granted:Play()
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0, math.rad(-5), 0))
			task.wait()
		end
	end
end

Promt2.Triggered:Connect(function(p)
	OpenDoor2(p)
end)```
1 Like

Odd, now when on any of the teamsallowed teams…it does the same thing, it just keeps swinging 5 out and not going -5 in when close prompt used. Yet the door works as it should on any team not on the list.

So try using not, maybe it will work then? This is really weird, I’ve never seen anything like this.

(if not table.find(teamsallowed, tostring(Player.Team)) then)

This actually just screwed up any code under.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.