buildbutton.MouseButton1Click:Connect(function()
player:SetAttribute("isbuilding", not player:GetAttribute("isbuilding"))
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(.4)
local isbuildingGoal = {Position = UDim2.fromScale(.017,.019)}
local isNotBuildingGoal = {Position = UDim2.fromScale(-.25,.019)}
if player:GetAttribute("isbuilding") == true then
buildframe1.Visible = true
local tween = TweenService:Create(buildframe1,tweenInfo,isbuildingGoal)
tween:Play()
else
local tween = TweenService:Create(buildframe1,tweenInfo,isNotBuildingGoal)
tween:Play()
tween.Completed:Wait()
if tween.PlaybackState == Enum.PlaybackState.Completed then
buildframe1.Visible = false
end
end
end)
You have to store when the last tween happened, then check after the tween is over that the time of the last update is the same before setting the frame to not be visible.
local lastUpdate
buildbutton.MouseButton1Click:Connect(function()
local now = os.clock()
lastUpdate = now
-- ...
if player:GetAttribute("isbuilding") then
-- ...
else
-- tween position
task.delay(0.4, function()
if lastUpdate == now then
buildFrame1.Visible = false
end
end)
end
end)