I’m working on a project, but I’ve run into a problem that I haven’t been able to solve. I tried using Roblox’s AI and other AI tools, but they haven’t been very helpful.
The issue is as follows: when selecting a team through a script connected to a UI located in the StarterGui
, the player is correctly assigned to the team. However, to obtain the team’s objects, a ProximityPrompt is used, which checks if the player is part of the team.
The problem is that this ProximityPrompt does not recognize the player as being on the team if they joined through the UI. On the other hand, if the player joins the team via a Spawn with the AllowTeamChangeOnTouch
option enabled, or if they are assigned to the team using a Khol’s Admin command, then the ProximityPrompt does detect them correctly and allows interaction.
Script to change to the team
local function assignTeam()
print("Botón presionado, comprobando whitelist...")
if whitelist[playerName] then
local teamName = whitelist[playerName]
local assignedTeam = Teams:FindFirstChild(teamName)
if assignedTeam then
player.Team = assignedTeam
print("Jugador asignado al equipo: " .. teamName)
local teamAssignedEvent = ReplicatedStorage:WaitForChild("TeamAssigned")
teamAssignedEvent:FireServer(teamName)
screenGui.Enabled = false
disableEffects()
task.wait(0.1)
teleportToSpawn(teamName)
else
warn("El equipo '" .. teamName .. "' no existe en Teams.")
end
else
warn("El jugador " .. playerName .. " no está en la whitelist.")
end
end
Script to get the items in the proximity prompt
-- Referencias a los objetos
local part = script.Parent -- El Part que tiene el ProximityPrompt
local proximityPrompt = part:WaitForChild("ProximityPrompt")
local serverStorage = game:GetService("ServerStorage")
local equipos = game:GetService("Teams") -- Accedemos a los equipos
local equipo = "Policía Judicial" -- Nombre del equipo que puede recibir los items
-- Lista de objetos que queremos entregar
local objetosAEntregar = {
"Tarjeta Policía", -- Estos son los nombres de los objetos en ServerStorage
"Pistola",
"Grilletes"
}
-- Función para entregar objetos al jugador
local function darItems(player)
-- Verifica si el jugador está en el equipo correcto
if player.Team and player.Team.Name == equipo then
-- Recorre la lista de objetos y da los objetos desde ServerStorage
for _, nombreObjeto in ipairs(objetosAEntregar) do
local objeto = serverStorage:FindFirstChild(nombreObjeto) -- Busca el objeto en ServerStorage
if objeto then
local clon = objeto:Clone() -- Clona el objeto
clon.Parent = player.Backpack -- Coloca el objeto en la mochila del jugador
else
warn("No se encontró el objeto: " .. nombreObjeto) -- Si no se encuentra el objeto, muestra un mensaje de advertencia
end
end
else
warn(player.Name .. " no está en el equipo de " .. equipo)
end
end
-- Evento para cuando el jugador interactúa con el ProximityPrompt
proximityPrompt.Triggered:Connect(function(player)
-- Verificamos si el jugador está en el equipo antes de darle los items
if player.Team == nil then
warn(player.Name .. " no está asignado a ningún equipo.")
else
-- Si está en un equipo, verificamos si está en el equipo correcto
if player.Team.Name == equipo then
darItems(player)
else
warn(player.Name .. " no está en el equipo " .. equipo)
end
end
end)
-- Escuchar el evento remoto para actualizar el estado del equipo
local replicatedStorage = game:GetService("ReplicatedStorage")
local teamAssignedEvent = replicatedStorage:WaitForChild("TeamAssigned")
teamAssignedEvent.OnServerEvent:Connect(function(player, teamName)
if player.Team and player.Team.Name == teamName then
print(player.Name .. " ha sido asignado correctamente al equipo " .. teamName)
else
warn(player.Name .. " no está en el equipo " .. teamName)
end
end)