Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

TweenPosition cause a delay on Gui Button?

Asked by 6 years ago

After I click on the GUI, the code executes, but have to wait 5 seconds or less for me to click the Gui again, how can I fix this?

local frame = script.Parent.Parent.Parent:WaitForChild("Test")
local open = false
script.Parent.MouseButton1Down:connect(function()
if open == false then
    frame:TweenPosition(UDim2.new(0.5, 0,0.1, 0), "Out", "Bounce", 1)
    open = true
else
    frame:TweenPosition(UDim2.new(0.5, 0,-1, 0), "Out", "Bounce", 1)
    open = false
end
end)

1 answer

Log in to vote
0
Answered by
UgOsMiLy 1074 Moderation Voter
6 years ago
Edited 6 years ago

This is because you have not set the override property to true. Also, try this script; it's more efficient.

local frame = script.Parent.Parent.Parent:WaitForChild("Test")
local open = false
script.Parent.MouseButton1Down:Connect(function()
    open = not open
    frame:TweenPosition(UDim2.new(0.5, 0,(open and 0.1) or -1, 0), "Out", "Bounce", 1, true)
end)

The true on line 5 will allow the tween to reverse midway.

0
`connect` is deprecated ;) Goulstem 8144 — 6y
0
I edited it. It says "connect" now ;) UgOsMiLy 1074 — 6y
Ad

Answer this question