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:

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)
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:

   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!

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