Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

3 comments

0

Im pretty sure if you set open value to true it stops the loop. Im not sure tho

0

it sets it to true after the function has already ran so that is not the case.

0

I think it's "Clicked" instead of mouse click.

1 answer

✓ Accepted answer

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)

8 comments

0

Is your gate a Model or a Part? if it's a model, then this code won't work.

0

throws error for a bad argument

0

fixed what was causing the error but the gate still does not move.

0

Is the gate a part or a model?

0

Maybe try and changing the CFrame instead of the position

0

its a union

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.

0

obviously the gate is anchored.

This discussion is preserved as it was. New answers, comments, and votes are closed.