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)
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.
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!