Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this script wait 5 sec before doing it's thing?

Asked by 5 years ago
local player = game.Players.LocalPlayer

local lead_exp = player:WaitForChild("Exp")

local exp_var = lead_exp.Value

local lead_level = player:WaitForChild("leaderstats").Levels

local level_var = lead_level.Value

local lead_coins = player:WaitForChild('leaderstats').Coins

local coins_var = lead_coins.Value

local player = game.Players.LocalPlayer

local lead_coins = player:WaitForChild('leaderstats').Coins

local coins_var = lead_coins.Value

while true do

--Remember it is a loop!

lead_exp = player:WaitForChild("Exp")

if exp_var < lead_exp.Value and script.Parent.Parent.EXP.Frame.ExpLoaded.Value == true and not coins_var < lead_coins.Value then

local gave = lead_exp.Value - exp_var

script.Parent.Exp.Visible = true

script.Parent.Exp.Position = UDim2.new(0.5,0,0.5,0)

script.Parent.Exp.TextLabel.Text = gave

script.Parent.Exp:TweenPosition(UDim2.new(0,0,1,0),"Out","Quint",3,true)

wait(2)

script.Parent.Exp.Visible = false

script.Parent.Exp.Position = UDim2.new(0.5,0,0.5,0)

exp_var = lead_exp.Value

if level_var < lead_level.Value and script.Parent.Parent.EXP.Frame.ExpLoaded.Value == true then

local gave = lead_level.Value

script.Parent.Level.Visible = true

script.Parent.Level.Position = UDim2.new(0.5,0,2,0)

script.Parent.Level.TextLabel.Text = gave

script.Parent.Level["Level Up!"]:Play()

script.Parent.Level:TweenPosition(UDim2.new(0.5,0,0.5,0),"Out","Quint",1,true)

wait(4.5)

script.Parent.Level.Visible = false

script.Parent.Level["Level Up!"]:Stop()

script.Parent.Level.Position = UDim2.new(0.5,0,2,0)

level_var = lead_level.Value

end

if script.Parent.Parent.EXP.Frame.Levels.Text ~= "Loading..." then

level_var = lead_level.Value

script.Parent.Parent.EXP.Frame.ExpLoaded.Value = true

end

if coins_var < lead_coins.Value and exp_var < lead_exp.Value and script.Parent.Parent.EXP.Frame.ExpLoaded.Value == true then

local gave = lead_coins.Value - coins_var

local gave2 = lead_exp.Value - exp_var

script.Parent.Exp.Visible = true

script.Parent.CoinCollect.TextLabel.Text = gave.." Coins"

script.Parent.CoinCollect.Visible = true

script.Parent.Exp.Position = UDim2.new(0.5,0,0.5,0)

script.Parent.Exp.TextLabel.Text = gave2

script.Parent.CoinCollect.Music:Play()

script.Parent.Exp:TweenPosition(UDim2.new(0,0,1,0),"Out","Quint",3,true)

wait(2)

script.Parent.Exp.Visible = false

script.Parent.Exp.Position = UDim2.new(0.5,0,0.5,0)

exp_var = lead_exp.Value

wait(tonumber(script.Parent.CoinCollect.Music.TimeLength)-0.01)

script.Parent.CoinCollect.Visible = false

coins_var = lead_coins.Value

end

wait()

end

Yes, sorry for B A D I N D E N T A T I O N, but I just copy-pasted and #StackEdit did this.

When I get both exp and coins:

if coins_var < lead_coins.Value and exp_var < lead_exp.Value and script.Parent.Parent.EXP.Frame.ExpLoaded.Value == true then

(When this runs) it waits 5 seconds and tween the position and shows the gui. also the music plays after 5 seconds.

Why does this do that?

Please don't post 'Bad Indentation' in the comments.

0
Before I can give you an answer I need to be able to read the code. Let's not repeat variables (Player) and let's move the :WaitForChild outside of the loop. You only have to wait once. BlackOrange3343 2676 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

On lines 39, 61, and 101 you have waits two of them are wait(2) and one is wait(4.5) was that a mistake? I hope this helped.

0
Those are lines of code that will wait for :TweenPosition() to finish and make the ImageLabel Invisible. tree_tree00 48 — 5y
Ad

Answer this question