How can I make a proximity prompt that can be triggered by only players on a certain team?

1. What I would like to achieve : A proximity prompt that can be triggered only by players that are on a certain team. (example: Players on the team named “Cashiers” can trigger the “Checkout” prompt while the players on the team named “Customers” can not do such thing)
2. The issue : It is not working at ALL, tried a couple of methods on the forum but none of them work.
3. What I have tried to solve this issue :

local prompt = script.Parent
local player = game:GetService("Players").LocalPlayer

prompt.Triggered:Connect(function()
	if player.Team == "cashier" then
		print("triggered")
	else
		print("false")
	end
end)

It is placed in a LocalScript

Any sort of help would be greatly appreciated.

2 Likes

Try this

local prompt = script.Parent
local player = game:GetService("Players").LocalPlayer

prompt.Triggered:Connect(function()
	if player.TeamColor == game.Teams.cashier.TeamColor then
		print("triggered")
	else
		print("false")
	end
end)

I think it’s because you’re using a LocalScript, which is under the prompt which will make it nonfunctional. Try using a server-side script with this code:

local prompt = script.Parent --assuming the server script is under the prompt
prompt.Triggered:Connect(function(player)
	if player.Team == "cashier" then
		print("triggered")
	else
		print("false")
	end
end)

What’s different here is that it’s a server-side script now, so it can actually run and detect the prompt. It also sets a temporary variable “player” as the player who activated it. If this doesn’t work, try putting a print statement directly under this line:

prompt.Triggered:Connect(function()

So we can see if it’s actually detecting it at all. Good luck!

The reason it won’t work when you’re using a team name is because it’s looking for a team. In order to make the proximity prompt work as expected, you have to either use the team color, as the first message said, 2nd you can use the current one but you’d have to do game.Teams.TeamName, or 3rd just add .Name to Player.Team (creating Player.Team.Name)

You are basically giving it a string instead of the object it’s looking for.

It prints this in the output : Workspace.Part.ProximityPrompt.Script:5: attempt to index nil with ‘TeamColor’

It prints the false statement even if the player is on the team

“Teamname” is not a valid propriety of teams but I tried with .Name as well but it did not work either

I’m not too experienced on Teams, since that’s an older built-in Roblox feature. However, after looking at it a bit, I understand. I would say use .Name, but that’s been suggested. Try printing the team name and see what it prints.

print(player.Team.Name)

It should print “cashier” or “customer”. If it says:
attempt to index nil with "Name" (or something like that) then the team is nil. If this is intentional that it’s sometimes nil, you should check in the script like this:

local prompt = script.Parent
prompt.Triggered:Connect(function(player)
if player.Team then
	if player.Team.Name == "cashier" then
		print("triggered")
	else
		print("false")
	end
end
end)

If it’s not intentional, then idk set the team. If the team is not nil, the team is “cashier”, and it still doesn’t recognize, then we can try something else. We can have a variable for the team object and check if it’s the exact thing, like this:

local prompt = script.Parent
local cashierTeam = game.Teams:WaitForChild("cashier") --i used wait for child bc i'm not sure if it's necessary for teams
prompt.Triggered:Connect(function(player)
	if player.Team == cashierTeam then
		print("triggered")
	else
		print("false")
	end
end)

Any errors after this I can not explain. Hope this works!

1 Like

It has worked, thank you very much for the assistance.

1 Like

Well obviously you replace Teamname with the teams name… it’s a placeholder for the team.

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