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