Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a script detect a specific part and destroy it?

Asked by 4 years ago

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:

01local event = game.ReplicatedStorage.Events.ForcefieldEvent
02 
03 
04event.OnServerEvent:Connect(function(player)
05    local upperTorso = player.Character.UpperTorso
06    local weld = Instance.new("WeldConstraint",upperTorso)
07    local cFF  = Instance.new("Part",workspace)
08    cFF.Anchored = false
09    cFF.CanCollide = false
10    cFF.Size =  Vector3.new(11.87, 11.87, 11.87)
11    cFF.Shape = "Ball"
12    cFF.Material = Enum.Material.SmoothPlastic
13    cFF.Position = upperTorso.Position
14    weld.Part0 = upperTorso
15    weld.Part1 = cFF
View all 24 lines...
0
Do you have a localscript which send Mouse.Target to this script? rabbi99 714 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

I noticed an error that pretty much renders the whole script pointless:

1cFF.Touched:Connect(function(hit)
2     if hit.Parent:FindFirstChild("BlueOrb") then
3         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

01local event = game.ReplicatedStorage.Events.ForcefieldEvent
02 
03 
04event.OnServerEvent:Connect(function(player)
05    local Character =  player.Character or player.CharacterAdded:wait()  
06    local upperTorso = player.Character.UpperTorso
07    local weld = Instance.new("WeldConstraint",upperTorso)
08    local cFF  = Instance.new("Part",workspace)
09    local click = Instance.new()   
10    cFF.Anchored = false
11    cFF.CanCollide = false
12    cFF.Size =  Vector3.new(11.87, 11.87, 11.87)
13    cFF.Shape = "Ball"
14    cFF.Material = Enum.Material.SmoothPlastic
15    cFF.Position = upperTorso.Position
View all 31 lines...

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!

0
Works ty! AronIZOdd 12 — 4y
0
No problem, but will you please click the checkmark near my answer so that others know it's been answered? TheOnlineItalian213 99 — 4y
Ad

Answer this question