How to get rid of blink in the tweening gui

Hi, can someone help me get rid of the blink in the tweening gui, this is the video

and this is the script

local buildbutton = script.Parent.buildbutton
local buildframe1 = script.Parent.buildframe1

player:GetAttributeChangedSignal("isbuilding"):Connect(function()
	if player:GetAttribute("isbuilding") == true then
		buildbutton.BorderColor3 = Color3.new(0, 0.666667, 0)
	else
		buildbutton.BorderColor3 = Color3.new(0.298039, 0.298039, 0.298039)
	end
end)
buildbutton.MouseButton1Click:Connect(function()
	player:SetAttribute("isbuilding", not player:GetAttribute("isbuilding"))
	
	if player:GetAttribute("isbuilding") == true then
		--buildframe1.Position = UDim2.new(-0.25, 0,0.019, 0)
		buildframe1.Visible = true
		buildframe1:TweenPosition(UDim2.new(0.017, 0,0.019, 0), nil, nil, 0.4, true)
	else
		--buildframe1.Position = UDim2.new(0.017, 0,0.019, 0)
		buildframe1:TweenPosition(UDim2.new(-0.25, 0,0.019, 0), nil, nil, 0.4, true)
		task.wait(0.4)
		if player:GetAttribute("isbuilding") == false then buildframe1.Visible = false end
	end
end)

sorry for messy script

(Move this to #help-and-feedback:scripting-support ! they know how to script better than we do (probably)

done like what you tell me to do.

1 Like
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)

does this work?

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)

THX!, you very fix my issue right now, thank you for the code

1 Like

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