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

Why does the part anchor in mid air?

Asked by 7 years ago
Edited 7 years ago

Why does the part anchor in mid air? I want it to anchor the moment it touches the ground. Also, I want it to anchor on top of a part if it falls on top of it. What is the solution? Here is a GIF of what it does: http://www.giphy.com/gifs/l2JhzIRAvRu8HOScw

while true do
    Part = Instance.new("Part", game.Workspace)
    Part.BrickColor = BrickColor.Random()
    Part.Material = "SmoothPlastic"
    Part.Position = Vector3.new(0, 128, 0)
    Part.BottomSurface = "Smooth"
    Part.TopSurface = "Smooth"
    function onTouched(hit)
        if hit.ClassName == "Part" then
            Part.Anchored = true
        end
    end
    Part.Touched:connect(onTouched)
    wait(0.5)
end

Thanks!

0
You could add a check to the if statement in the onTouched function to check if the hit name is Baseplate. shayner32 478 — 7y
0
Sorry I did not mention I wasn't it to anchor if it falls on top of the other parts, I added it to my question. GatitosMansion 187 — 7y

2 answers

Log in to vote
2
Answered by
shayner32 478 Trusted Moderation Voter
7 years ago

Here, there's a few little tweaks to the code.

while true do
    Part = Instance.new("Part", game.Workspace)
    Part.BrickColor = BrickColor.Random()
    Part.Material = "SmoothPlastic"
    Part.Position = Vector3.new(0, 128, 0)
    Part.BottomSurface = "Smooth"
    Part.TopSurface = "Smooth"
    function onTouched(hit)
        if hit:IsA("BasePart") and (Part.Anchored or hit.Name == "Baseplate") then -- Check if the hit is a part, and then check if the part is already anchored (to stack), or if the hit name is baseplate (to properly establish the beginning)
            Part.Anchored = true
        end
    end
    Part.Touched:connect(onTouched)
    wait(0.5)
end

0
Thanks it works! GatitosMansion 187 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

You have in the function onTouched part when it hits another object with the classname "Part", it will anchor. In order to fix this, you need to do this:

function onTouched(hit)
if hit.Name == "PartName" then
Part.Anchored = true
end

What I did was I changed it so the script will check for the name of the object that hit it instead of the classname being "Part". Hope this helped! :)

0
So just rename the part that will make it anchored whatever you want and it should work. :) ragingskull182 67 — 7y
0
Please be sure you are aware of the situation before posting an answer. You lack a proper end to the if statement/function, and you just took my comment on the question and made it into an answer. shayner32 478 — 7y

Answer this question