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

How would I make this function unanchor and destroy?

Asked by
262187 45
8 years ago

I'm attempting to make a brick that has a function and when "BuildingBrick" touches it, it will delete. The function works but only for un-anchored "BuildingBrick". How would I make the function un-anchor the part(BuildingBrick) and destroy it when it touches the brick with the script? Edit: I'm using CFraming.

What I attempted to do:

function onTouched(hit) 
if hit.Name == 'BuildingBrick' and hit.Anchored then
hit.Anchored = false
hit:Destroy()
end
end
script.Parent.Touched:connect(onTouched) 

I've also tried

function onTouched(hit) 
if hit.Name == 'BuildingBrick' or hit.Anchored then 
hit:Destroy()
end
end
script.Parent.Touched:connect(onTouched) 


and it dosen't work

0
Are you CFraming BuildingBrick towards the other brick? dyler3 1510 — 8y
0
Yes. 262187 45 — 8y
0
Ok, look here: http://wiki.roblox.com/index.php?title=Touched Under the notes section, it states, that the touched event will not fire if a brick is being cframed through another brick dyler3 1510 — 8y
0
Ah, So this is just not possible? 262187 45 — 8y
View all comments (3 more)
0
Well it is, but you might need to do it a different way. An example would be to use a script to find all the edges of each block, and from there use a Changed() event to find out whether they're touching whenever the part is moved. There's probably more efficient ways to do it, but this is just an example. dyler3 1510 — 8y
0
Oh, I see Thanks! 262187 45 — 8y
0
Np :P dyler3 1510 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

As someone mentioned in the comments, the Touched event will not fire if you are CFraming a part through another part. However - you could use a while loop and the GetTouchingParts() method to see if said part is touching the part. Script:

while wait(.1) do -- Not foolproof, because if the part takes less than .1 seconds to move through the part, it won't necessarily pick up the touch
    local parts = script.Parent:GetTouchingParts()
    for i, part in pairs(parts) do
        if part.Name == "BuildingBrick" and part.Anchored then
            part.Anchored = false
            part:Destroy()
        end
    end
end
0
Thanks this is what i wanted ! 262187 45 — 8y
0
Is there any chance this script could be modified for it to work while cancollide is set to false? 262187 45 — 8y
Ad

Answer this question