Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does the part anchor in mid air?

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!

2 comments

0

You could add a check to the if statement in the onTouched function to check if the hit name is Baseplate.

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.

2 answers

✓ Accepted answer

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

1 comment

0

Thanks it works!

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

2 comments

0

So just rename the part that will make it anchored whatever you want and it should work. :)

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.