What's wrong with this UI Tween

Hey devs,

I’m trying to make a little coin animation where when you collect/coins three coins come from the bottom of your screen and tween into the display of where your coin count is recorded. My code yields no errors, yet does not work at all.

I checked it over and over, and the one thing I do see is a flash of an oversized coin in the bottom right of my screen for a split second.

My code is basic, and should work:

local plr = game.Players.LocalPlayer
local TS = game:GetService("TweenService")
local Tinfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)
local DTinfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, .2)
local ETinfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, .4)
local Goals = {}
Goals.Position = UDim2.new(0.033, 0,0.13, 0)

local Rpos = UDim2.new(3.25, 0,4.386, 0)
local coin = script.Parent


local leaderstats = plr:WaitForChild("leaderstats")

leaderstats.Coins.Changed:Connect(function()
	local function CoinClone()
		local C = coin:Clone()
		C.Parent = script.Parent.Parent.Parent
		C.Name = "Coin Clone"
		
		C.Position = Rpos
		
		local D = coin:Clone()
		D.Parent = script.Parent.Parent.Parent
		D.Name = "Coin Clone"
		
		D.Position = Rpos
		local E = coin:Clone()
		E.Parent = script.Parent.Parent.Parent
		E.Name = "Coin Clone"
		
		E.Position = Rpos
		
		C.Visible = true
		wait(.2)
		D.Visible = true
		wait(.2)
		E.Visible = true
		wait(.2)
		local CCoinTween = TS:Create(C, Tinfo, Goals):Play()
		local DCoinTween = TS:Create(C, DTinfo, Goals):Play()
		local ECoinTween = TS:Create(C, ETinfo, Goals):Play()
		wait(1)
		C:Destroy()
		wait(.2)
		D:Destroy()
		wait(.2)
		E:Destroy()
	end
	
	CoinClone()
	
	
	
	
end)

Can anyone help me - I can elaborate on details if needed.

Each of these are Tweening the same object (the initial coin, referenced by C), instead of referencing separate coins for each Tween. This means that there are three animations being played on that object at once, which is likely why you observed a singular oversized coin when the animation plays.

By updating the second and third Tweens to reference the other coins that were created, that would likely resolve the issue.


Revised Code:

local CCoinTween = TS:Create(C, Tinfo, Goals):Play()
local DCoinTween = TS:Create(D, DTinfo, Goals):Play()
local ECoinTween = TS:Create(E, ETinfo, Goals):Play()

Of course, what a stupid error. Thanks!

1 Like

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