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

Saw always stays on never spins the saw for some reason?

my switcalways stays on but the saw never spins and it wont let the switch turn on heres my script

local saw = game.Workspace.Saw
script.Parent.ClickDetector.MouseClick:connect(function()
	if Off then
	On = script.Parent.CFrame == CFrame.new(0,0,0) + CFrame.fromEulerAnglesXYZ(-45,0,0)
	while true do
Saw.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0) * CFrame.fromEulerAnglesXYZ(0, 0, -0.1)
wait(0.001)
end
	if On then
		Off = script.Parent.CFrame == CFrame.new(0,0,0) + CFrame.fromEulerAnglesXYZ(0,0,0)
		while true do
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0) * CFrame.fromEulerAnglesXYZ(0, 0, 0)
wait(0.001)
end
	end
	end
	end)

1 answer

You are using a while loop that never terminates, therefore it will never stop. You need to include a condition in the loop so it knows when to terminate:

local saw = game.Workspace.Saw
local isOn = false

script.Parent.ClickDetector.MouseClick:connect(function()
	if isOn then
		isOn = false
	else
		isOn = true
		while isOn do
			Saw.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0, 0, -0.1)
			wait()
		end
	end
end)

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