Not able to change position

I am making an end for my obby. I made it so that when a button is touched, parts fall down like frames in a movie. I want to return it to its original state once it is done. However, when I tried to change the position of the object, I get an error saying that the object is not a part of the model it was grouped to. Below is my code and some screenshots. (I know the code is messy, bare with me)

image

image

function onTouch(part)

local humanoid = part.Parent:FindFirstChild("Humanoid")

if (humanoid ~= nil) then -- if a humanoid exists, then
wait(0.5)
game.Workspace.Ending1.EndScreen1.CanCollide = false
game.Workspace.Ending1.EndScreen1.Anchored = false
wait(1)
game.Workspace.Ending1.EndScreen1.Anchored = true
wait(1)
game.Workspace.Ending2.EndScreen2.CanCollide = false
game.Workspace.Ending2.EndScreen2.Anchored = false
wait(1)
game.Workspace.Ending2.EndScreen2.Anchored = true
wait(1)
game.Workspace.Ending3.EndScreen3.CanCollide = false
game.Workspace.Ending3.EndScreen3.Anchored = false
wait(1)
game.Workspace.Ending3.EndScreen3.Anchored = true
wait(1)
game.Workspace.Ending4.EndScreen4.CanCollide = false
game.Workspace.Ending4.EndScreen4.Anchored = false
wait(1)
game.Workspace.Ending4.EndScreen4.Anchored = true
wait(1)
game.Workspace.Ending5.EndScreen5.CanCollide = false
game.Workspace.Ending5.EndScreen5.Anchored = false
wait(1)
game.Workspace.Ending5.EndScreen5.Anchored = true
wait(1)
game.Workspace.Ending6.EndScreen6.CanCollide = false
game.Workspace.Ending6.EndScreen6.Anchored = false
wait(1)
game.Workspace.Ending6.EndScreen6.Anchored = true
wait(1)
game.Workspace.Ending7.EndScreen7.CanCollide = false
game.Workspace.Ending7.EndScreen7.Anchored = false
wait(1.5)
game.Workspace.Ending7.EndScreen7.Anchored = true
wait(1.5)
game.Workspace.Ending8.EndScreen8.CanCollide = false
game.Workspace.Ending8.EndScreen8.Anchored = false
wait(1)
game.Workspace.Ending8.EndScreen8.Anchored = true
wait(1)
game.Workspace.Ending1.EndScreen1.CanCollide = true -- here is the error, it says that EndScreen1 is not a valid member of model. I also stopped adding the new positions here b/c it was not working
game.Workspace.Ending1.Endscreen1.Position = Vector3.new(657,164.75,166.25)
game.Workspace.Ending1.EndScreen1.Anchored = true
wait(2)
game.Workspace.Ending2.EndScreen2.CanCollide = true
game.Workspace.Ending2.EndScreen2.Anchored = true
wait(2)
game.Workspace.Ending3.EndScreen3.CanCollide = true
game.Workspace.Ending3.EndScreen3.Anchored = true
wait(2)
game.Workspace.Ending4.EndScreen4.CanCollide = true
game.Workspace.Ending4.EndScreen4.Anchored = true
wait(2)
game.Workspace.Ending5.EndScreen5.CanCollide = true
game.Workspace.Ending5.EndScreen5.Anchored = true
wait(2)
game.Workspace.Ending6.EndScreen6.CanCollide = true
game.Workspace.Ending6.EndScreen6.Anchored = true
wait(2)
game.Workspace.Ending7.EndScreen7.CanCollide = true
game.Workspace.Ending7.EndScreen7.Anchored = true
wait(2)
game.Workspace.Ending8.EndScreen8.CanCollide = true
game.Workspace.Ending8.EndScreen8.Anchored = true
end

end

script.Parent.Touched:connect(onTouch)

Thanks

Check if there’s another model named “Ending1”, that might be possibly the reason.
Names are case-sensitive, perhaps you made a typo on this line?

game.Workspace.Ending1.Endscreen1.Position = Vector3.new(657,164.75,166.25)
                          ^

(humanoid ~= nil) is redundant, you can achieve the same thing by doing “if (humanoid) then” in this case, “:connect” is deprecated IIRC, I suggest you use “:Connect” instead

1 Like

Oh yes, thank you, I did have a typo in the capitalization of the S in EndScreen. I also fixed the connect. It works now!