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

Why does my script only rotate the part the first time?

I have a script that rotates a valve.

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
	if script.Parent.Value.Value == false then
		for i = 1, 45, 1 do
			script.Parent.CFrame = CFrame.new(script.Parent.Position) * CFrame.Angles(math.rad(script.Parent.Orientation.X - 2),0,0)
			wait()
		end
	else
		for i = 1, 45, 1 do
			script.Parent.CFrame = CFrame.new(script.Parent.Position) * CFrame.Angles(math.rad(script.Parent.Orientation.X + 2),0,0)
			wait()
		end
	end
end)

The first time I click it, it works. Every time after it just kinda vibrates.

1 answer

✓ Accepted answer

You forgot to toggle your Bool value

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
     local bool = script.Parent.Value
    if  bool.Value == false then
         bool.Value = not bool.Value
        for i = 1, 45, 1 do
            script.Parent.CFrame = CFrame.new(script.Parent.Position) * CFrame.Angles(math.rad(script.Parent.Orientation.X - 2),0,0)
            wait()
        end
    else
         bool.Value = not bool.Value
        for i = 1, 45, 1 do
            script.Parent.CFrame = CFrame.new(script.Parent.Position) * CFrame.Angles(math.rad(script.Parent.Orientation.X + 2),0,0)
            wait()
        end
    end
end)

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