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

How would i keep a Gui invisible for a certain amount of time?

Asked by 9 years ago

I made an intro and a Gun shop Gui, Obviously they're both Screen Gui's, but anyways i have been trying to make Gun shop Gui invisible until the intro is over and here is what i came up with

game.StarterGui.GunShopGui.Box.Visible = false
game.starterGui.GunShopGui.OpenAndClose.Visible = false
wait(1)
script.Parent.Visible = true
script.Parent.Parent.Music:Play()
script.Parent.Text = "[ Loading ]"
wait(1)
script.Parent.Text = "[ 5% ]"
wait(0.15)
script.Parent.Text = "[ 7% ]"
wait(0.15)
script.Parent.Text = "[ 9% ]"
wait(0.15)
script.Parent.Text = "[ 20% ]"
wait(0.15)
script.Parent.Text = "[ 35% ]"
wait(0.15)
script.Parent.Text = "[ 34% ]"
wait(0.15)
script.Parent.Text = "[ 35% ]"
wait(0.15)
script.Parent.Text = "[ 35% ]"
wait(0.15)
script.Parent.Text = "[ 35% ]"
wait(0.15)
script.Parent.Text = "[ 35% ]"
wait(0.15)
script.Parent.Text = "[ 35% ]"
wait(0.15)
script.Parent.Text = "[ 60% ]"
wait(0.15)
script.Parent.Text = "[ 60% ]"
wait(0.15)
script.Parent.Text = "[ 74% ]"
wait(0.15)
script.Parent.Text = "[ 83% ]"
wait(0.15)
script.Parent.Text = "[ 83% ]"
wait(0.15)
script.Parent.Text = "[ 83% ]"
wait(0.15)
script.Parent.Text = "[ 97% ]"
wait(1)
script.Parent.Text = "[ 100% ]"
wait(0.05)
script.Parent.Transparency = 0.05
wait(0.05)
script.Parent.Transparency = 0.10
wait(0.05)
script.Parent.Transparency = 0.15
wait(0.05)
script.Parent.Transparency = 0.20
wait(0.05)
script.Parent.Transparency = 0.25
wait(0.05)
script.Parent.Transparency = 0.30
wait(0.05)
script.Parent.Transparency = 0.35
wait(0.05)
script.Parent.Transparency = 0.40
wait(0.05)
script.Parent.Transparency = 0.45
wait(0.05)
script.Parent.Transparency = 0.50
wait(0.05)
script.Parent.Transparency = 0.55
wait(0.05)
script.Parent.Transparency = 0.60
wait(0.05)
script.Parent.Transparency = 0.65
wait(0.05)
script.Parent.Transparency = 0.70
wait(0.05)
script.Parent.Transparency = 0.75
wait(0.05)
script.Parent.Transparency = 0.80
wait(0.05)
script.Parent.Transparency = 0.85
wait(0.05)
script.Parent.Transparency = 0.90
wait(0.05)
script.Parent.Transparency = 0.95
wait(0.05)
script.Parent.Transparency = 1.00
wait(.1)
script.Parent.Parent.Music:Stop()
wait(.1)
game.StarterGui.GunShopGui.Box.Visible = false
game.starterGui.GunShopGui.OpenAndClose.Visible = false



The intro worked fine after that but the Gun shop Gui never appeared, Is there any way i could fix this? And just some extra Information , that might or might not be helpful but both Screen Gui's are by them self not, with one Gui inside another one.

0
Uhm, line 88 and 89, you said when its over it should turn visible. why is visible = false then iNicklas 215 — 9y
0
yeah, it was a mistake purplemetro3421 5 — 9y

2 answers

Log in to vote
2
Answered by
davness 376 Moderation Voter
9 years ago

I think the whole script could be cleaned up.

First. You will never get your Shop back if you assign your gui's visiblility property as false

game.StarterGui.GunShopGui.Box.Visible = false
game.starterGui.GunShopGui.OpenAndClose.Visible = false
--The rest of the script
game.StarterGui.GunShopGui.Box.Visible = true
game.starterGui.GunShopGui.OpenAndClose.Visible = true

Second. You are making the changes above on theStarterGui, or in a "GuiStorage", as I call it. So you will only get the results once you respawn you character. To prevent this, you can use the script.Parent technique as you did on the intro. Assuming the intro is like script.Parent.Parent.Parent inside the StarterGui (if not, correct by yourself)

script.Parent.Parent.Parent.GunShopGui.Box.Visible = false
script.Parent.Parent.Parent.GunShopGui.OpenAndClose.Visible = false
--The rest of the script
script.Parent.Parent.Parent.GunShopGui.Box.Visible = true
script.Parent.Parent.Parent.GunShopGui.OpenAndClose.Visible = true

And finally, you can make the transparency system look more fluid. Instead of writing lots and lots of lines, you can just use a while or a for loop:

INSTEAD OF:

script.Parent.Transparency = 0.05
wait(0.05)
script.Parent.Transparency = 0.10
wait(0.05)
script.Parent.Transparency = 0.15
wait(0.05)
script.Parent.Transparency = 0.20
wait(0.05)
script.Parent.Transparency = 0.25
wait(0.05)
script.Parent.Transparency = 0.30
wait(0.05)
script.Parent.Transparency = 0.35
wait(0.05)
script.Parent.Transparency = 0.40
wait(0.05)
script.Parent.Transparency = 0.45
wait(0.05)
script.Parent.Transparency = 0.50
wait(0.05)
script.Parent.Transparency = 0.55
wait(0.05)
script.Parent.Transparency = 0.60
wait(0.05)
script.Parent.Transparency = 0.65
wait(0.05)
script.Parent.Transparency = 0.70
wait(0.05)
script.Parent.Transparency = 0.75
wait(0.05)
script.Parent.Transparency = 0.80
wait(0.05)
script.Parent.Transparency = 0.85
wait(0.05)
script.Parent.Transparency = 0.90
wait(0.05)
script.Parent.Transparency = 0.95
wait(0.05)
script.Parent.Transparency = 1.00
wait(.1)
script.Parent.Parent.Music:Stop()
wait(.1)

Use this:

while script.Parent.Transparency < 1 do --while the label's transparency value is lower than 1, or else, while you can see the label
script.Parent.Transparency = script.Parent.Transparency + 0.05 -- add some transpareny to the label
wait() --fluid process and crash prevent
end
wait(.1)
script.Parent.Parent.Music:Stop()
wait(.1)

Or this:

for i = 1,20 do -- because 0.05*20 = 1
script.Parent.Transparency = script.Parent.Transparency + 0.05 -- add some transpareny to the label
wait() --fluid process
end
wait(.1)
script.Parent.Parent.Music:Stop()
wait(.1)

And what about this loading lines? Can't we do the same? Obviously we can.

INSTEAD OF

script.Parent.Text = "[ 5% ]"
wait(0.15)
script.Parent.Text = "[ 7% ]"
wait(0.15)
script.Parent.Text = "[ 9% ]"
wait(0.15)
script.Parent.Text = "[ 20% ]"
wait(0.15)
script.Parent.Text = "[ 35% ]"
wait(0.15)
script.Parent.Text = "[ 34% ]"
wait(0.15)
script.Parent.Text = "[ 35% ]"
wait(0.15)
script.Parent.Text = "[ 35% ]"
wait(0.15)
script.Parent.Text = "[ 35% ]"
wait(0.15)
script.Parent.Text = "[ 35% ]"
wait(0.15)
script.Parent.Text = "[ 35% ]"
wait(0.15)
script.Parent.Text = "[ 60% ]"
wait(0.15)
script.Parent.Text = "[ 60% ]"
wait(0.15)
script.Parent.Text = "[ 74% ]"
wait(0.15)
script.Parent.Text = "[ 83% ]"
wait(0.15)
script.Parent.Text = "[ 83% ]"
wait(0.15)
script.Parent.Text = "[ 83% ]"
wait(0.15)
script.Parent.Text = "[ 97% ]"
wait(1)
script.Parent.Text = "[ 100% ]"

Use in pairs function

local l = {5, 7, 9, 20, 35, 34, 35, 35, 35, 35, 35, 60, 60, 74, 83, 83, 83, 97, 100}

for i,v in pairs(l) do
script.Parent.Text = "[ "..v.."% ]"
wait (0.15)
end

Whole script

local l = {5, 7, 9, 20, 35, 34, 35, 35, 35, 35, 35, 60, 60, 74, 83, 83, 83, 97, 100}
script.Parent.Parent.Parent.GunShopGui.Box.Visible = false
script.Parent.Parent.Parent.GunShopGui.OpenAndClose.Visible = false

wait(1)
script.Parent.Visible = true
script.Parent.Parent.Music:Play()
script.Parent.Text = "[ Loading ]"
wait(1)

-- the in pairs loop
for i,v in pairs(l) do
script.Parent.Text = "[ "..v.."% ]"
wait (0.15)
end

--loop 1 (choose one)

while script.Parent.Transparency < 1 do --while the label's transparency value is lower than 1, or else, while you can see the label
script.Parent.Transparency = script.Parent.Transparency + 0.05 -- add some transpareny to the label
wait() --fluid process and crash prevent
end

--loop 2 (choose one)

for i = 1,20 do -- because 0.05*20 = 1
script.Parent.Transparency = script.Parent.Transparency + 0.05 -- add some transpareny to the label
wait() --fluid process
end

wait(.1)
script.Parent.Parent.Music:Stop()
wait(.1)
script.Parent.Parent.Parent.GunShopGui.Box.Visible = true
script.Parent.Parent.Parent.GunShopGui.OpenAndClose.Visible = true

Do you see? If you try to learn something more, you can reduce your script lines!! In this case, the lines were reduced in more than 50% !!!

0
Heh, nice clean up! Michael007800 144 — 9y
0
Thanks, i should've looked at the wiki first! purplemetro3421 5 — 9y
0
no problem but know a things is always useful :) davness 376 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

It's a mistake on your end!

game.StarterGui.GunShopGui.Box.Visible = false
game.starterGui.GunShopGui.OpenAndClose.Visible = false
wait(1)
script.Parent.Visible = true
script.Parent.Parent.Music:Play()
script.Parent.Text = "[ Loading ]"
wait(1)
script.Parent.Text = "[ 5% ]"
wait(0.15)
script.Parent.Text = "[ 7% ]"
wait(0.15)
script.Parent.Text = "[ 9% ]"
wait(0.15)
script.Parent.Text = "[ 20% ]"
wait(0.15)
script.Parent.Text = "[ 35% ]"
wait(0.15)
script.Parent.Text = "[ 34% ]"
wait(0.15)
script.Parent.Text = "[ 35% ]"
wait(0.15)
script.Parent.Text = "[ 35% ]"
wait(0.15)
script.Parent.Text = "[ 35% ]"
wait(0.15)
script.Parent.Text = "[ 35% ]"
wait(0.15)
script.Parent.Text = "[ 35% ]"
wait(0.15)
script.Parent.Text = "[ 60% ]"
wait(0.15)
script.Parent.Text = "[ 60% ]"
wait(0.15)
script.Parent.Text = "[ 74% ]"
wait(0.15)
script.Parent.Text = "[ 83% ]"
wait(0.15)
script.Parent.Text = "[ 83% ]"
wait(0.15)
script.Parent.Text = "[ 83% ]"
wait(0.15)
script.Parent.Text = "[ 97% ]"
wait(1)
script.Parent.Text = "[ 100% ]"
wait(0.05)
script.Parent.Transparency = 0.05
wait(0.05)
script.Parent.Transparency = 0.10
wait(0.05)
script.Parent.Transparency = 0.15
wait(0.05)
script.Parent.Transparency = 0.20
wait(0.05)
script.Parent.Transparency = 0.25
wait(0.05)
script.Parent.Transparency = 0.30
wait(0.05)
script.Parent.Transparency = 0.35
wait(0.05)
script.Parent.Transparency = 0.40
wait(0.05)
script.Parent.Transparency = 0.45
wait(0.05)
script.Parent.Transparency = 0.50
wait(0.05)
script.Parent.Transparency = 0.55
wait(0.05)
script.Parent.Transparency = 0.60
wait(0.05)
script.Parent.Transparency = 0.65
wait(0.05)
script.Parent.Transparency = 0.70
wait(0.05)
script.Parent.Transparency = 0.75
wait(0.05)
script.Parent.Transparency = 0.80
wait(0.05)
script.Parent.Transparency = 0.85
wait(0.05)
script.Parent.Transparency = 0.90
wait(0.05)
script.Parent.Transparency = 0.95
wait(0.05)
script.Parent.Transparency = 1.00
wait(.1)
script.Parent.Parent.Music:Stop()
wait(.1)
game.StarterGui.GunShopGui.Box.Visible = true -- You set this to false, not true
game.starterGui.GunShopGui.OpenAndClose.Visible = true -- Same here! true not false!
0
Why don't you use the for loop? woodengop 1134 — 9y
0
Oh my! i never noticed that, as i told dav, i should have looked into the wiki but i should have also looked at the script before i posted this forum :/ purplemetro3421 5 — 9y

Answer this question