I've been working on a script that makes a brick move downward. Instead of making it move until it's Y position is in a specific spot, I wanted it to stop when it touches another brick.
So far I have:
repeat moonHold.CFrame = CFrame.new(moonHold.Position.X,moonHold.Position.Y-1, moonHold.Position.Z) --print(moonHold.Position.Y) (testing purposes) wait() until moonHold.Touched:connect(function(Part) if Part.Name ~= "Moon" then debounce = true end end)
And the Until
block is the problem, yet I have no idea what to do there. I tried using a Boolean
in order to activate the second block of code but that doesn't loop the brick like I wanted it to. I also tried to paste in the code into the if statement but that didn't work either (Unless I did something wrong.)
Any help?
I have 2 scripts and a BoolValue.
Both script are normal script.
In Script 1: Part Touching
script.Parent.Touched:Connect(function(toch) -- Run if part is touched if script.Parent.Move.Value == true then -- if the BoolValue value is not false script.Parent.Move.Value = false -- Set it to false end end)
Script 2: Moving the part
while wait(0.1) do -- Every 0.1sec run this local move = script.Parent:WaitForChild("Move") -- wait for the child called Move, which is the BoolValue if move then -- If the child is found then if move.Value == true then -- check if the value is true script.Parent.Position = Vector3.new(script.Parent.Position.X, script.Parent.Position.Y - 1, script.Parent.Position.Z ) -- Move the Y coordinate of part down 1 studs end end end