I'm trying to have selection boxes appear over a player when you hover your cursor over that player. I had it working before where I had a server script put a click detector and a selection box in every person using a playerAdded event.
local Players = game:GetService("Players")
function onCharacterAdded(character)
if not character:FindFirstChild("SelectionBox") then
local ClickDetector = script.ClickDetector:Clone()
ClickDetector.Parent = character
end
end
local function onPlayerAdded(player)
if player.Character then
onCharacterAdded(player.Character)
end
player.CharacterAdded:Connect(onCharacterAdded)
end
for i, player in pairs(Players:GetPlayers()) do
onPlayerAdded(player)
end
Players.PlayerAdded:Connect(onPlayerAdded)
Then, I had a server script inside the click detector that made the selection box visible and invisible.
local repStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local remote = repStorage:WaitForChild("PlrRequest")
script.Parent.MouseHoverEnter:Connect(function()
SelectionBox.Visible = true
end)
script.Parent.MouseHoverLeave:Connect(function()
SelectionBox.Visible = false
end)
script.Parent.MouseClick:Connect(function(playerWhoClicked)
remote:FireClient(playerWhoClicked, Players.LocalPlayer.Name)
end)
However, the problem with that was when you hovered your cursor over the person the selection box would appear for all players. So, I then replaced the server script inside the click detector with a local script with the same code and now the selection boxes wont even appear. Is there anyway I can have the selection boxes appear only in the client that hovered their cursor over the player?

1 comment
You need to have the local script be a descendant of the player and fix the variable path of the ClickDetector: https://developer.roblox.com/api-reference/class/ClickDetector