How do i stop a section in a script

hi,

how do i make a part in a script to only work once until the next part of the script is done

script.Parent.MouseHover:Connect(function()
    script.Parent:TweenPosition(script.Parent.Position + UDmin.new(0,10,0,0), "Out", "Sine", 1)
    script.Parent.MouseLeave:Connect(function()
        script.Parent:TweenPosition(script.Parent.Position + UDmin.new(0,-10,0,0), "Out", "Sine", 1)
    end)
end)

So when the mouse enters it will move but only once. Then when the mouse leaves, it only goes -10 once until the mouse enters part is active again.

1 Like

you put “end)” below both of the functions. This should work:

script.Parent.MouseHover:Connect(function()
    script.Parent:TweenPosition(script.Parent.Position + UDmin.new(0,10,0,0), "Out", "Sine", 1)
end)
    script.Parent.MouseLeave:Connect(function()
        script.Parent:TweenPosition(script.Parent.Position + UDmin.new(0,-10,0,0), "Out", "Sine", 1)
end)

yes but when i put my mouse over the frame, it keeps moving forward.

i also wrote some typos but ignore that

Is your tween set to loop/repeat?

What do you mean by that. empty space

Try making the tween outside the function using tweenservice instead, then use the functions that come with it like tween:play() and tween:cancel()

I think i found the issue. This works but the tween can be interrupted. So how should I stop that?

Instead of using MouseHover use MouseEnter and then MouseLeave. MouseHover is triggered every Frame the Mouse is inside the GuiObject, but MouseEnter is only triggered when entering.

Did you read what I just said, or

oh sorry the scripts suppose to be

script.Parent.MouseEnter:Connect(function()
	script.Parent:TweenPosition(script.Parent.Position + UDim2.new(0,10,0,0), "Out", "Sine", 1, true)
end)
script.Parent.MouseLeave:Connect(function()
	script.Parent:TweenPosition(script.Parent.Position + UDim2.new(0,-10,0,0), "Out", "Sine", 1, true)
end)

sorry for the typos

1 Like

yeah. I was trying to pin your message to the one I wrote…

I also think it would end up with the same result but I think that the way im trying to go with will be easier. No offense tho.

That should work am I mistaken?

Maybe you could use Debounce? When mouse entered or left change the debounce everytime.

no because the tween where it moves +10 can be interrupted by -10.
https://gyazo.com/cf8bc8e439cd0b82dd8ea1ffa4c00612

Lol sorry, but yeah make the tween first like

local TweenService = game:GetService('TweenService')

local info = TweenInfo.new() -- from here you can set all kinds of things for the tween to do, even change color

local tween = TweenService:create(gui, info)

Tween:Play()
Tween:Pause()
Tween:Cancel()

Then add , false after the 1 in the tweens.

Either that or instead of offsetting its position you set it to a specific location.

it doesn’t work. Just tryed it.