Error with moving parts then another parts is touched

how how to make a lot of “KillBricks” in the folder named “Obstacle” to lift up.
script is local and located inside of folder, in folder two parts “Platform3” that can be touched but inside this each parts i have another part that if touched then “KillBricks” is changing position

 local part = workspace.P3.Platform3
local moving = workspace.Obstacle:GetDescendants("Part")
part.Touched:Connect(function(hit)
	print("work")
	moving.CFrame = CFrame.new(0, -25, 0)
end)

This goes to a fixed position that is -25 in the Y axis, which means it goes downwards and is probably below ground at this point.

i even tried to do 50 but nothing worked

In order to lift up a part you can simply do part.Position += Vector3.new(0, 25, 0) -- add's 25 on the Y axis

You also try to call GetDescendants() with a parameter “Part”, altough the method doesn’t take any params.

You also make a new Index CFrame for a table, and not change the parts CFrames

Firstly; we need to get all the KillBricks. In your case, it’d be best to make a seperate folder with JUST the kill bricks
Then to get them, you do local movingParts = workspace.Obstacle.KillBricks:GetChildren()

Secondly;
You loop trough each one, adding the position:

for _, part in movingParts do
part.Position += Vector3.new(0, 25, 0)
end
local part = workspace.P3:GetDescendants("Part")
local moving = workspace.Obstacle:GetDescendants("Part")
part.Touched:Connect(function(hit)
	print("work")
	moving.CFrame = CFrame.new(0, 50, 0)
end)

i need to collect get parts in folder and multiple move up

I already explained how you do that. Please read my response

still have error because in my code its says attempt to index nil
part.Touched:Connect(function(hit)

You just copy pasted the code i wrote without trying to understand it.
You need to incorporate what i wrote into your code

This place is for learning, not for spoonfeeding

can answer how me check if part name equals KillBrick or it is a part because i idk how get each part but if use GetDescendants its returns array but not each part

:GetDescendants() returns an array will all descendants of the object
Like i said; move your killbricks to another folder named “KillBricks” and then call :GetChildren() – (not :GetDescendants())

That will give you every object in that folder. If you only put parts in that folder, you dont need to do any checks that would waste performance

but i have multiple KillBricks GetChildren() return only 1

:GetChildren() does not return only 1 child
Read here: Instance | Documentation - Roblox Creator Hub

image
if you were to call :GetChildren() on this screen gui, it would give you {MainFrame}
if you had another instance on the same level, you would get that too

Calling :GetDescendants() gives you EVERYTHING under the ScreenGui :
image

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.