I’m trying to write a script that makes a part go down until it touches another brick. It still seems to go down even after it touches another brick. Here’s my script.
local test = false
script.Parent.Touched:connect(function(hit)
test = true
end)
repeat
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0, -0.1, 0) --You can change the value here to change how the block expands.
wait(0.001)
until test == true
I’m not sure where in the script I messed up, or if I forgot to add something
It’d be interesting to know also the size of your parts. If they are nanometric no wonder why nothing happens: collisions aren’t properly calculated due to your parts skipping one another.
Also, I personally hate repeat until. I suggest doing something like:
local test = false;
script.Parent.Touched.Connect(function(hit) -- it's "Connect", not "connect"
test
end)
while not test do -- first checks the condition then runs the code, unlike repeat until loops
script.Parent.CFrame = script.Parent.CFrame - Vector3.new(0,.1,0); -- looks better with positive arguments
task.wait(); -- task.wait() is more precise than wait()
end
Also please notice that it’s “Connect”, not “connect”,
local test = false;
script.Parent.Touched:Connect(function(hit)
test = true;
end)
while not test do
script.Parent.CFrame = script.Parent.CFrame - Vector3.new(0,.1,0);
task.wait();
end
Here’s how it turned out (The script is on the blue brick)
Please can you turn them off and re-activate? Make sure it’s on for both. I don’t exactly remember what’s the right symbol, but I remember that when at least one of multiple selections, but not all, have that property on it’d show some white stuff.
Your beginning script was almost perfect. I would change wait(0.001) to use task.wait(), and instead of using a Touched event you can just check for :GetPartsInPart().
Touched does fire when you move an anchored object programmatically into an unanchored part, too. It only behaves this way when both parts are not affected by physics.
Touched is a physics based connection (Has to be moving). Since artificially changing the position isn’t considered moving, use GetPartsInPart if you are trying to tell if they are touching.