Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make a part move until another brick touches it?

Asked by 7 years ago

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?

1 answer

Log in to vote
0
Answered by
thesit123 509 Moderation Voter
7 years ago

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
0
Hope it helped! thesit123 509 — 7y
0
The thing is, i want it to be in one consecutive script, meaning I'd want the movement to to be in a "repeat until ___" all together. Marioluigi35 7 — 7y
0
Okay... Have 1 script and a bool value. Remove the code after repeat(Your Script) and remove while wait() do(My Script), and paste the rest of my 2nd script to your script after the repeat. And then remove after Until(Your Script) and paste my 1st script in after (Your Script) until. thesit123 509 — 7y
Ad

Answer this question