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

Remove possible welds from a part? (hit)

Asked by
14dark14 167
4 years ago

When a part touched another part (lava) all welds that are attached to the part get destroyed

example - an unanchored car hits a rock and the part that touched the rock falls of the car ( like in those old 2010 games )

the car is welded together so it doesn't fall apart.

v - the script ( lava part ) - v

script.Parent.Touched:Connect(function(hit)
local all = hit:FindFirstChild("Weld")
    all:Destroy()
end)

I could just make the part disappear with a script, but that's lame.

2 answers

Log in to vote
1
Answered by 4 years ago
script.Parent.Touched:Connect(function(hit)
    local all = hit:FindFirstChildOfClass("Weld") or hit.Parent:FindFirstChildOfClass("Weld")
    repeat
    all = hit:FindFirstChildOfClass("Weld") or hit.Parent:FindFirstChildOfClass("Weld")
    if all then
        all:Destroy()
    end
    until all == nil
end)

I haven't tested it but maybe it would work

0
Nice, works, but quick question - how to make the script ignore if a human touches it? Please scroll down this post and see my answer. my fix didn't work. 14dark14 167 — 4y
0
Nice, works, but quick question - how to make the script ignore if a human touches it? Please scroll down this post and see my answer. my fix didn't work. 14dark14 167 — 4y
Ad
Log in to vote
0
Answered by
14dark14 167
4 years ago
Edited 4 years ago
script.Parent.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid ~= nil then
        return
    else
    local all = hit:FindFirstChildOfClass("Weld") or hit.Parent:FindFirstChildOfClass("Weld")
    repeat
    all = hit:FindFirstChildOfClass("Weld") or hit.Parent:FindFirstChildOfClass("Weld")
    if all then
        all:Destroy()
    end
    until all == nil
end
end)
0
u basically took my post and added on to it but ok HappyTimIsHim 652 — 4y

Answer this question