Hello everyone! I would like to get some help. What I need to do is make the proximity prompt visible only for “Team 1” and not for the rest of the teams. What am I doing wrong? Currently, it keeps showing for everyone.
localscript in element2:
-- Get the ProximityPrompt
local proximityPrompt = script.Parent:FindFirstChildOfClass("ProximityPrompt")
-- Define the team name that should see the ProximityPrompt
local teamNameToShowPrompt = "Team 1" -- Replace with your team's name
-- Connect to the PromptShown event of the ProximityPrompt
proximityPrompt.PromptShown:Connect(function(player)
print("PromptShown event triggered for " .. player.Name)
-- Check if the player belongs to the specific team
local character = player.Character
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
local team = humanoid and humanoid.Team
if team then
print(player.Name .. "'s team: " .. team.Name)
if team.Name == teamNameToShowPrompt then
-- If the player is in the correct team, allow the ProximityPrompt to be shown
print(player.Name .. " from team " .. teamNameToShowPrompt .. " sees the ProximityPrompt")
return true
else
-- If the player is not in the correct team, prevent the ProximityPrompt from being shown
print(player.Name .. " does NOT belong to team " .. teamNameToShowPrompt .. " and doesn't see the ProximityPrompt")
return false
end
else
print(player.Name .. " doesn't have an assigned team and doesn't see the ProximityPrompt")
return false
end
end)
I tried to do this, but it’s not working. What could be wrong?
server script:
-- ServerScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
-- Create a RemoteEvent for communication between server and client
local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("showProxPrompt")
local elementProximityPrompt = script.Parent.ElementoProxPrompt
-- Connect to the PromptShown event of the ProximityPrompt
elementProximityPrompt.PromptShown:Connect(function(player)
-- Check if the player belongs to the specific team
local character = player.Character
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
local team = humanoid and humanoid.Team
if team and team.Name == "Team 2" then
-- If the player is in the correct team, trigger the event to the client with true value
remoteEvent:FireClient(player, elementProximityPrompt, true)
print(player.Name .. " from Team1 sees the ProximityPrompt")
else
-- If the player is not in the correct team, trigger the event to the client with false value
remoteEvent:FireClient(player, elementProximityPrompt, false)
print(player.Name .. " does NOT belong to Team1 and doesn't see the ProximityPrompt")
end
end)
localscript:
-- LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
-- Wait for the RemoteEvent to exist in ReplicatedStorage
local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("showProxPrompt")
-- Connect to the remote event to handle the visibility of the ProximityPrompt on the client
remoteEvent.OnClientEvent:Connect(function(prompt, state)
-- Set the visibility of the ProximityPrompt based on the received value
prompt.Enabled = state
print("ProximityPrompt visibility set to " .. tostring(state))
end)
I just made that change, and the proximity prompt is still showing. I want to hide it for Team 1 to test.
server:
-- ServerScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
-- Create a RemoteEvent for communication between server and client
local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("showProxPrompt")
local elementProximityPrompt = script.Parent.ElementoProxPrompt
-- Connect to the PromptShown event of the ProximityPrompt
elementProximityPrompt.PromptShown:Connect(function(player)
-- Check if the player belongs to the specific team
local humanoid = player.Character and player.Character:FindFirstChild("Humanoid")
local team = humanoid and humanoid.Team
if team and team.Name == "Team 2" then
-- If the player is in the correct team, trigger the event to the client with true value
remoteEvent:FireClient(player, elementProximityPrompt, true)
print(player.Name .. " from Team 2 sees the ProximityPrompt. Event fired with visibility set to true.")
else
-- If the player is not in the correct team, trigger the event to the client with false value
remoteEvent:FireClient(player, elementProximityPrompt, false)
print(player.Name .. " does NOT belong to Team 2 and doesn't see the ProximityPrompt. Event fired with visibility set to false.")
end
end)
localscript:
-- LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
-- Wait for the RemoteEvent to exist in ReplicatedStorage
local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("showProxPrompt")
-- Connect to the remote event to handle the visibility of the ProximityPrompt on the client
remoteEvent.OnClientEvent:Connect(function(prompt, state)
-- Set the visibility of the ProximityPrompt based on the received value
prompt.Enabled = state
print("ProximityPrompt visibility set to " .. tostring(state))
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
-- Create a RemoteEvent for communication between server and client
local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("showProxPrompt")
local elementProximityPrompt = script.Parent.ElementoProxPrompt
-- Connect to the PromptShown event of the ProximityPrompt
elementProximityPrompt.PromptShown:Connect(function(player)
-- Check if the player belongs to the specific team
local team = player.Team
if team and team == game.Teams["Team 2"] then
-- If the player is in the correct team, trigger the event to the client with true value
remoteEvent:FireClient(player, elementProximityPrompt, true)
print(player.Name .. " from Team 2 sees the ProximityPrompt. Event fired with visibility set to true.")
elseif team ~= game.Teams["Team 2"] then
-- If the player is not in the correct team, trigger the event to the client with false value
remoteEvent:FireClient(player, elementProximityPrompt, false)
print(player.Name .. " does NOT belong to Team 2 and doesn't see the ProximityPrompt. Event fired with visibility set to false.")
end
end)
– Local Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
-- Wait for the RemoteEvent to exist in ReplicatedStorage
local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("showProxPrompt")
-- Connect to the remote event to handle the visibility of the ProximityPrompt on the client
remoteEvent.OnClientEvent:Connect(function(prompt, state)
-- Set the visibility of the ProximityPrompt based on the received value
prompt.Enabled = state
print("ProximityPrompt visibility set to " .. tostring(state))
end)
Or you might aswell just make a loop inside of a Client-sided script:
while task.wait() do
for _, Players in pairs(game.Players:GetPlayers()) do
if Players.Team == game.Teams["Team 2"] then
for _, Prompts in pairs(workspace:GetDescendants()) do
if Prompts.Name == "ElementoProxPrompt" then
game:GetService("ReplicatedStorage"):WaitForChild("showProxPrompt"):FireClient(Players, Prompts, true)
end
end
elseif Players.Team ~= game.Teams["Team 2"] then
for _, Prompts in pairs(workspace:GetDescendants()) do
if Prompts.Name == "ElementoProxPrompt" then
game:GetService("ReplicatedStorage"):WaitForChild("showProxPrompt"):FireClient(Players, Prompts, false)
end
end
end
end
end
I tried your code, and it didn’t work. I also adjusted my code to this new format, and it still didn’t work.
updated version
script:
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("showProxPrompt")
local elementProximityPrompt = script.Parent.ElementoProxPrompt
local function UpdatePlayersPromptVisibility()
for _, player in pairs(Players:GetPlayers()) do
if player.Team == Teams["Team 2"] then
remoteEvent:FireClient(player, elementProximityPrompt, true)
else
remoteEvent:FireClient(player, elementProximityPrompt, false)
end
end
end
UpdatePlayersPromptVisibility()
localscript:
local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("showProxPrompt")
remoteEvent.OnClientEvent:Connect(function(prompt, status)
prompt.Enabled = status
print("ProximityPrompt visibility set to " .. tostring(status))
end)
local Player = game.Players.LocalPlayer;
wait();
local function CheckTeam()
for _, Prompts in pairs(workspace:GetDescendants()) do
if Prompts:IsA("ProximityPrompt") and Prompts.Name == Player.Team.Name then
Prompts.Enabled = true
elseif Prompts:IsA("ProximityPrompt") and Prompts.Name ~= Player.Team.Name then
Prompts.Enabled = false
end
end
end
CheckTeam();
11:05:53.515 Invalid or nil ProximityPrompt received from server. Received: nil - Cliente - LocalScript:15
script:
-- Server Script
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("showProxPrompt")
local elementProximityPrompt = script.Parent:WaitForChild("ElementoProxPrompt")
-- Print the value of elementProximityPrompt before sending it to clients
print("Initial elementProximityPrompt value:", elementProximityPrompt)
local function UpdatePlayersPromptVisibility()
for _, player in pairs(Players:GetPlayers()) do
-- Check if the player is in Team 2
if player.Team == Teams["Team 2"] then
-- Fire the remote event to show the ProximityPrompt for players in Team 2
remoteEvent:FireClient(player, elementProximityPrompt, true)
else
-- Fire the remote event to hide the ProximityPrompt for players not in Team 2
remoteEvent:FireClient(player, elementProximityPrompt, false)
end
end
end
-- Call the function when a player is added to the game
Players.PlayerAdded:Connect(function(player)
UpdatePlayersPromptVisibility()
end)
localscript:
-- LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("showProxPrompt")
remoteEvent.OnClientEvent:Connect(function(prompt, status)
-- Check if the received prompt is a valid ProximityPrompt
if typeof(prompt) == "Instance" and prompt:IsA("ProximityPrompt") then
-- Set the visibility of the ProximityPrompt based on the received status
prompt.Enabled = status
print("ProximityPrompt visibility set to " .. tostring(status))
else
-- Warn if an invalid or nil ProximityPrompt is received
warn("Invalid or nil ProximityPrompt received from server. Received:", prompt)
end
end)