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

This script is not moving the part, why not? extra words to be able to post?

Asked by 5 years ago

It is running the loops successfully but the parts' position in the workspace is not changing.

detector = script.Parent
gate = game.Workspace.Gate


open = false
position = gate.Position.Y
detector.MouseClick:Connect(function()
    if open == false then
        detector.MaxActivationDistance = 0
        for i = 1,17 do
            print("moved")
            position = position + 1
            wait(0.5)
        end
        detector.MaxActivationDistance = 15
        open = true
    else
        detector.MaxActivationDistance = 0
        for i = 1,17 do
            position = position - 1
            wait(0.5)
        end
        open = false
        detector.MaxActivationDistance = 15
    end
end)
0
Im pretty sure if you set open value to true it stops the loop. Im not sure tho iikinqMxster 9 — 5y
0
it sets it to true after the function has already ran so that is not the case. FallenZalio 99 — 5y
0
I think it's "Clicked" instead of mouse click. sngnn 274 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

Try using Vector3 to change the part's position. Here's my code:

detector = script.Parent
gate = game.Workspace.Gate

open = false

detector.MouseClick:Connect(function()
    if open == false then
        detector.MaxActivationDistance = 0
        for i = 1,17 do
            print("moved")
            gate.Position = gate.Position + Vector3.new(0, 1, 0)
            wait(0.5)
        end
        detector.MaxActivationDistance = 15
        open = true
    else
        detector.MaxActivationDistance = 0
        for i = 1,17 do
            gate.Position = gate.Position + Vector3.new(0, -1, 0)
            wait(0.5)
        end
        open = false
        detector.MaxActivationDistance = 15
    end
end)
0
Is your gate a Model or a Part? if it's a model, then this code won't work. AbusedCocopuff4 105 — 5y
0
throws error for a bad argument FallenZalio 99 — 5y
0
fixed what was causing the error but the gate still does not move. FallenZalio 99 — 5y
0
Is the gate a part or a model? AbusedCocopuff4 105 — 5y
View all comments (4 more)
0
Maybe try and changing the CFrame instead of the position AbusedCocopuff4 105 — 5y
0
its a union FallenZalio 99 — 5y
0
Is your gate even anchored? Also, if you set position and the part ends up inside of another part, the gate won't move properly. Try using the CFrame property to set position instead. laughablehaha 494 — 5y
0
obviously the gate is anchored. FallenZalio 99 — 5y
Ad

Answer this question