This is the code I have
local Tool = script.Parent local player = game.Players.LocalPlayer Tool.Equipped:Connect(function(Mouse) Mouse.Button1Down:Connect(function() if Mouse.Target == game.Workspace.EmeraldBlock.Part then player.PlayerGui.ScreenGui.Frame.Visible = true player.PlayerGui.ScreenGui.Frame.Frame1:TweenSize(UDim2.new(1.01, 0,0.63, 0), nil, "Linear", 5, false ) end end) Mouse.Button1Up:Connect(function() if Mouse.Target ~= game.Workspace.EmeraldBlock.Part then player.PlayerGui.ScreenGui.Frame.Visible = false player.PlayerGui.ScreenGui.Frame.Frame1:TweenSize(UDim2.new(0, 0,.63,0), nil, nil, .01, true ) end end) end)
What happens is when I move my mouse away from the block while i'm holding down mouse button 1, the GUI continues to tween, even though the mouse target is no longer that part
Hello. You have to use Mouse.Move
with the :Disconnect()
function. Try this:
local Tool = script.Parent local player = game.Players.LocalPlayer Tool.Equipped:Connect(function(Mouse) Mouse.Button1Down:Connect(function() if Mouse.Target == game.Workspace.EmeraldBlock.Part then player.PlayerGui.ScreenGui.Frame.Visible = true player.PlayerGui.ScreenGui.Frame.Frame1:TweenSize(UDim2.new(1.01, 0,0.63, 0), nil, "Linear", 5, false ) local move local function onMove() player.PlayerGui.ScreenGui.Frame.Visible = false player.PlayerGui.ScreenGui.Frame.Frame1:TweenSize(UDim2.new(0, 0,.63,0), nil, nil, .01, true ) move:Disconnect() end move = Mouse.Move:Connect(onMove) end end) Mouse.Button1Up:Connect(function() if Mouse.Target ~= game.Workspace.EmeraldBlock.Part then player.PlayerGui.ScreenGui.Frame.Visible = false player.PlayerGui.ScreenGui.Frame.Frame1:TweenSize(UDim2.new(0, 0,.63,0), nil, nil, .01, true ) end end) end)
When the mouse moves, the Frame turns invisible and tweens the Frame's Frame1. Then it disconnects the function. Please upvote and accept this question if it helped.