Tween playing too early?

Hello Developers
So i’ve been testing my game and when the round ends it will tween the leaderboard. But what happens is, at last 2 seconds. it tweened the leaderboard instantly. I’ve been having this problem for a while and try anything i could try to make it tween at the perfect time but sadly it wont work.


		print(MaxTime-(((MaxTime/3)-10)*3))
		task.wait(MaxTime-(((MaxTime/3)-10)*3))
		stats[drawer] = {Points/(CountTable()),CountTable()}
		for _, plyrsAvail in pairs(game.Players:GetPlayers()) do
			plyrsAvail:WaitForChild('PlayerGui'):WaitForChild('GameUi(wdoj21nd9nd)').Leaderboard:TweenPosition(UDim2.new(0,0,0,0),'Out','Back',1)
			for _, user in pairs(game.Players:GetPlayers()) do
				if stats[user.Name] then
					local scoresloading = game.ReplicatedStorage["scoretemplate(882dj8whdd)"]:Clone()
					scoresloading.Parent = plyrsAvail:WaitForChild('PlayerGui'):WaitForChild('GameUi(wdoj21nd9nd)').Leaderboard.List
					scoresloading.username.Text = user.Name
					scoresloading.scorechanges.Text = stats[user.Name][1]
					scoresloading.LayoutOrder = stats[user.Name][2]
				else
					local scoresloading = game.ReplicatedStorage["scoretemplate(882dj8whdd)"]:Clone()
					scoresloading.Parent = plyrsAvail:WaitForChild('PlayerGui'):WaitForChild('GameUi(wdoj21nd9nd)').Leaderboard.List
					scoresloading.username.Text = user.Name
					scoresloading.scorechanges.Text = '0'
					scoresloading.scorechanges.TextColor3 = Color3.fromRGB(255, 0, 0)
					scoresloading.LayoutOrder = 50
				end
			end
		end

Tween line that plays:

plyrsAvail:WaitForChild('PlayerGui'):WaitForChild('GameUi(wdoj21nd9nd)').Leaderboard:TweenPosition(UDim2.new(0,0,0,0),'Out','Back',1)

More Script information

local MaxTime = 120
Math
MaxTime = 120

task.wait((MaxTime/3)-10)
-- several script
task.wait((MaxTime/3)-10)
-- several script
task.wait((MaxTime/3)-10)
-- several script

MaxTime-(((MaxTime/3)-10)*3)
MaxTime/3 = 40
40-10 = 30
30*3 = 90
MaxTime-90 = 30
task.wait(30)
1 Like

Try utilizing task.delay or task.wait here the Roblox documentation for “task

i tried using task.wait() already so i tried task.delay() but it showed the leaderboard too early at 89 seconds left

Could you make a BindableEvent and fire this event when the round ends? Then play the tween?

Hmm, did you do task.delay([number]) ?
Because If yes you should do something like this:

task.delay([number], function()
   -- code right here.
end)

yes i did it like that.

Max characters

Unfornately not. I’ll try that and update you if it works!

it didn’t work sadly :frowning: i assume there was problem with the math. in task.wait(MaxTime-(((MaxTime/3)-10)*3)). it still played at 2 seconds. Variable MaxTime is 120

Heres one idea:

  1. Create a Script
  2. Parent that scripts into the current script
  3. Put the tween function Into that script
  4. Disable that script
  5. After the time ends enable that script

Second Idea:

  1. Utilize TweenInfo
  2. Create a saved Tween Using TweenInfo variable it something like local tween = -- tween info items right here
  3. After the time comes run [variable]:Play()

Doc for tweenInfo: TweenInfo

this is my script that i use to end the round.

local function EndRound()
	stats[drawer] = {Points/(CountTable()),CountTable()}
	for _, plyrsAvail in pairs(game.Players:GetPlayers()) do
		plyrsAvail:WaitForChild('PlayerGui'):WaitForChild('GameUi(wdoj21nd9nd)').Leaderboard:TweenPosition(UDim2.new(0,0,0,0),'Out','Back',1)
		for _, user in pairs(game.Players:GetPlayers()) do
			if stats[user.Name] then
				local scoresloading = game.ReplicatedStorage["scoretemplate(882dj8whdd)"]:Clone()
				scoresloading.Parent = plyrsAvail:WaitForChild('PlayerGui'):WaitForChild('GameUi(wdoj21nd9nd)').Leaderboard.List
				scoresloading.username.Text = user.Name
				scoresloading.scorechanges.Text = stats[user.Name][1]
				scoresloading.LayoutOrder = stats[user.Name][2]
			else
				local scoresloading = game.ReplicatedStorage["scoretemplate(882dj8whdd)"]:Clone()
				scoresloading.Parent = plyrsAvail:WaitForChild('PlayerGui'):WaitForChild('GameUi(wdoj21nd9nd)').Leaderboard.List
				scoresloading.username.Text = user.Name
				scoresloading.scorechanges.Text = '0'
				scoresloading.scorechanges.TextColor3 = Color3.fromRGB(255, 0, 0)
				scoresloading.LayoutOrder = 50
			end
		end
	end
	wait(5)
	for _, plyrsAvail in pairs(game.Players:GetPlayers()) do
		plyrsAvail:WaitForChild('PlayerGui'):WaitForChild('GameUi(wdoj21nd9nd)').Leaderboard:TweenPosition(UDim2.new(0,0,-1,0),'In','Back',1)
	end
	wait(1)
	for _, plyrsAvail in pairs(game.Players:GetPlayers()) do
		for _, listed in pairs(plyrsAvail:WaitForChild('PlayerGui'):WaitForChild('GameUi(wdoj21nd9nd)').Leaderboard.List:GetChildren()) do
			if listed:IsA('Frame') then
				listed:Destroy()
			end
		end
	end
	NewRound()
end

at here stats[drawer] it will be hard because that’s a table and the stats will be recorded using my chat function. so if i separate it it might cost a lots of work to connect the 2 or more function. I’ll try the second idea, hang on

Try Using TweenInfo Ig, it lets you store tweens then :Play(), :Stop() them.

Your 2nd idea kind of work but 2 or 1 second late from tweening

TweenInfo should not fail, I think your waits/delays are Incorrect
Please try It with different waits/delays If it works please mark my post as the solution :slight_smile:

well it kind of finally work at here MaxTime-((((MaxTime/3)-10)*3)+3 i added 3 on it from MaxTime-((((MaxTime/3)-10)*3) but thanks.

No problem, hope this helps you on your game…

1 Like

Pretty sure task.wait(3) when the round ends would’ve resolved your issue if implemented into the script correctly.