How would I change this so it uses tween service?

So I have this script for Cooldowns.
And right now I am using a for loop to change the size of the frame.

And it is well, as you can guess. It really un-smooth.

So how would I transfer this to tween service?

local event = game:GetService('ReplicatedStorage'):FindFirstChild('CooldownUI')


event.OnClientEvent:Connect(function(AttackNumber,CDTime)
	local frame = script.Parent:FindFirstChild(AttackNumber)
	
	print(frame.Name..' Has been found! WOOP WOOP')
	local cdFrame:Frame
	cdFrame = frame.CDF
	
	cdFrame.Visible = true
	
	local waitTime = CDTime / 10
	
	print(waitTime)
	for size = 1, 0,-0.1 do
		cdFrame.Size = UDim2.new(1,0,size,0)
		wait(waitTime)
	end
	cdFrame.Visible = false
	print('Cooldown over')
end)

Yes I am using Scale, not Offset.
I just need to tween the size TLDR

local event = game:GetService('ReplicatedStorage'):FindFirstChild('CooldownUI')
local tween = game:GetService("TweenService")
local TweenItself

event.OnClientEvent:Connect(function(AttackNumber,CDTime)
	local frame = script.Parent:FindFirstChild(AttackNumber)

	print(frame.Name..' Has been found! WOOP WOOP')
	local cdFrame:Frame
	cdFrame = frame.CDF

	cdFrame.Visible = true

	local waitTime = CDTime / 10

	print(waitTime)
	TweenItself = tween:Create(cdFrame,TweenInfo.new(CDTime),{Size = UDim2.new(1,0,1,0)})
	TweenItself:Play()
	TweenItself.Completed:Wait()
	TweenItself = nil
	cdFrame.Visible = false
	print('Cooldown over')
end)
1 Like

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