I am using filtering enabled, so I had to use remote events. Though when I did it without remote events it worked fine.
Also it's not just the character that's being removed, the player is being removed from the game.
Local Script
local selectionBox = Instance.new("SelectionBox")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
selectionBox.Parent = player:WaitForChild('PlayerGui')
local destroyPart = game.ReplicatedStorage.DestroyPart
mouse.Move:Connect(function()
local target = mouse.Target
if not target then return end
if target and target:IsA("BasePart") then
selectionBox.Adornee = target
else
selectionBox.Adornee = nil
end
end)
mouse.Button1Down:Connect(function()
local target = mouse.Target
if not target then return end
if target and target:IsA("BasePart") and selectionBox.Adornee and selectionBox.Adornee:IsA("BasePart") and not target:IsDescendantOf(player) and not target:IsDescendantOf(player.Character) then
print(target)
destroyPart:FireServer(target)
selectionBox.Adornee = nil
end
end)
Server Script:
local destroyPart = game.ReplicatedStorage.DestroyPart
destroyPart.OnServerEvent:Connect(function(part)
if not game.Players:GetPlayerFromCharacter(part.Parent) then
part:Destroy()
end
end)

1 comment
Thanks, I forgot all about the first parameter being the player.