Tween doesnt stop

Hi, so when a person’s mouse enters the button, it is supposed to be “shaking”.

I accomplish this by using math.random to get a random rotation. Then I tween the rotation of the button to that random number.

The problem with this is I want it to stop when the person’s mouse leaves. It is not doing that.

It keeps on shaking even though I don’t want it to. Can someone help?

script.Parent.MouseEnter:Connect(function(pos)
	while script.Parent.MouseEnter do
		task.wait()
		local randomrot = math.random(0, 10)
		local rotti = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
		local rottween = ts:Create(script.Parent, rotti, {Rotation = randomrot})
		rottween:Play()
		rottween.Completed:Wait()
	end
end)

script.Parent.MouseLeave:Connect(function(pos)
	local rotti = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
	local rottween = ts:Create(script.Parent, rotti, {Rotation = 5})
	rottween:Play()
end)
1 Like

You can just mention the previous tween outside the functions and use tween:Cancel()

1 Like

yeah but, then it wont be random every time

fixed by just using a boolean value and detecting if the boolean is true, it will run the tween!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.