So I have been having a problem where I made this orb that goes around the player and it activates when you click the left mouse button, but the problem is is that I wanna make the script destroy a specific part that hits it. But it does not do that, please help. Here is the code:
local event = game.ReplicatedStorage.Events.ForcefieldEvent event.OnServerEvent:Connect(function(player) local upperTorso = player.Character.UpperTorso local weld = Instance.new("WeldConstraint",upperTorso) local cFF = Instance.new("Part",workspace) cFF.Anchored = false cFF.CanCollide = false cFF.Size = Vector3.new(11.87, 11.87, 11.87) cFF.Shape = "Ball" cFF.Material = Enum.Material.SmoothPlastic cFF.Position = upperTorso.Position weld.Part0 = upperTorso weld.Part1 = cFF cFF.Transparency = 0.5 cFF.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("BlueOrb") then workspace.BlueOrb:Destroy() else print("Pass.") end end) end)
I noticed an error that pretty much renders the whole script pointless:
cFF.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("BlueOrb") then workspace.BlueOrb:Destroy()
"Touched" Is an event that is triggered only when a part collides into another, you should consider adding a ClickDetector inside cFF if you want the player to use the LeftMouseButton to destroy the part, and in that case the script would be
local event = game.ReplicatedStorage.Events.ForcefieldEvent event.OnServerEvent:Connect(function(player) local Character = player.Character or player.CharacterAdded:wait() local upperTorso = player.Character.UpperTorso local weld = Instance.new("WeldConstraint",upperTorso) local cFF = Instance.new("Part",workspace) local click = Instance.new() cFF.Anchored = false cFF.CanCollide = false cFF.Size = Vector3.new(11.87, 11.87, 11.87) cFF.Shape = "Ball" cFF.Material = Enum.Material.SmoothPlastic cFF.Position = upperTorso.Position cFF.Name = "BlueOrb" weld.Part0 = upperTorso weld.Part1 = cFF cFF.Transparency = 0.5 local debounce = false click.MouseClick:Connect(function(hit) if debounce == false then debounce = true workspace:FindFirstChild("BlueOrb") workspace.BlueOrb:Destroy() debounce = false else print("Pass.") end end) end)
Also sorry if this doesn't work as I didn't have the full script and couldn't test it out, if there are any problems please comment, hope this helps!