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

Why the hell does this for i loop go inverse when its grouped ?

Asked by 8 years ago

local buttonPressed = false script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") and not buttonPressed then buttonPressed = true for i = 16.3, 15.9, -0.01 do script.Parent.Position = Vector3.new(3.5,i,10) end script.Parent.BrickColor = BrickColor.new("Really red") buttonPressed = false end end)

I want to make a block go from 16.3 to 15.9 in the Y axis, and instead of going down it goes up. Can't understand why.

0
jJst make '-0.01' to '0.01'? lucas4114 607 — 8y

2 answers

Log in to vote
-1
Answered by 8 years ago

Position works weirdly. Since position detects collisions with other parts, the position changes to where it won't collide with anything. So your code is correct except you have to change 'Position' to 'CFrame'. This is how the code should be.

local buttonPressed = false


script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") and not buttonPressed then

            buttonPressed = true
            for i = 16.3, 15.9, -0.01 do
                script.Parent.CFrame  = CFrame.new(3.5,i,10) -- Here's the Change.
            end
            script.Parent.BrickColor = BrickColor.new("Really red")

            buttonPressed = false
        end
end)

Ad
Log in to vote
0
Answered by 8 years ago

While looking I've noticed you are using .Position =

That is very dangereous as it may move your part/model to a position different than expected, for example...

Imagine your part is inside a house... It's on the wall... It will move up or down. Change it to .CFrame = CFrame.new(...

Answer this question