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

I need help with GUI Switching. Anything I've done wrong?

Asked by 10 years ago

Alright. So I am creating a huge game universe, and I have a separate place reserved for the introduction. The introduction is basically a few ImageLabel GUI's which are scripted to activate in a sequence to resemble a sort of cutscene. There are no errors in the script.

The script is supposed to force each GUI to become visible and then invisible after an amount of time, and then teleport the player to the next place. However, what happens is that the GUI's don't become invisible OR visible at all! As a result, it just stays on the first frame. It does, however, teleport the player to the desired place. My script is posted below.


local player = script.Parent.Parent

game.StarterGui.ScreenGui.Q1.Visible = true
game.StarterGui.ScreenGui.Q2.Visible = false
game.StarterGui.ScreenGui.Q3.Visible = false
game.StarterGui.ScreenGui.Q4.Visible = false
game.StarterGui.ScreenGui.Q5.Visible = false
game.StarterGui.ScreenGui.Story.Visible = false
wait(2)
game.StarterGui.ScreenGui.Q1.Visible = false
game.StarterGui.ScreenGui.Q2.Visible = true
game.StarterGui.ScreenGui.Q3.Visible = false
game.StarterGui.ScreenGui.Q4.Visible = false
game.StarterGui.ScreenGui.Q5.Visible = false
game.StarterGui.ScreenGui.Story.Visible = false
wait(2)
game.StarterGui.ScreenGui.Q1.Visible = false
game.StarterGui.ScreenGui.Q2.Visible = false
game.StarterGui.ScreenGui.Q3.Visible = true
game.StarterGui.ScreenGui.Q4.Visible = false
game.StarterGui.ScreenGui.Q5.Visible = false
game.StarterGui.ScreenGui.Story.Visible = false
wait(2)
game.StarterGui.ScreenGui.Q1.Visible = false
game.StarterGui.ScreenGui.Q2.Visible = false
game.StarterGui.ScreenGui.Q3.Visible = false
game.StarterGui.ScreenGui.Q4.Visible = true
game.StarterGui.ScreenGui.Q5.Visible = false
game.StarterGui.ScreenGui.Story.Visible = false
wait(2)
game.StarterGui.ScreenGui.Q1.Visible = false
game.StarterGui.ScreenGui.Q2.Visible = false
game.StarterGui.ScreenGui.Q3.Visible = false
game.StarterGui.ScreenGui.Q4.Visible = false
game.StarterGui.ScreenGui.Q5.Visible = true
game.StarterGui.ScreenGui.Story.Visible = false
wait(5)
game.StarterGui.ScreenGui.Q1.Visible = false
game.StarterGui.ScreenGui.Q2.Visible = false
game.StarterGui.ScreenGui.Q3.Visible = false
game.StarterGui.ScreenGui.Q4.Visible = false
game.StarterGui.ScreenGui.Q5.Visible = false
game.StarterGui.ScreenGui.Story.Visible = true
wait(15)
if player then
    game:GetService("TeleportService"):TeleportToSpawnByName(73690355, "SpawnLocation", player)
    end

Any ideas?

0
There is a very simpler way to do this, try tables. I did this not long ago and it is much better, I could give you my GUI but I'm on mobile right now. IntellectualBeing 430 — 10y
0
Of course I will explain how everything works. IntellectualBeing 430 — 10y
0
Oh! Sure! This'll be a lot of help for my Universe! Of course, it's based off of the Elder Scrolls. Stravellia 0 — 10y
0
I'll need to do research, looking into tables. Stravellia 0 — 10y

2 answers

Log in to vote
1
Answered by
Dummiez 360 Moderation Voter
10 years ago

You're doing this on StarterGui, which is a parent of Game, not your player, thus is why you cannot see it.

-- Inside a LocalScript, parent in the StarterGui
local player = game.Players.LocalPlayer
local gui = script.Parent["ScreenGui"]

for i = 1, 5 do
wait(2)
gui.Q1.Visible = false
gui.Q2.Visible = false
gui.Q3.Visible = false
gui.Q4.Visible = false
gui.Q5.Visible = false
gui:findFirstChild("Q"..i).Visible = true
end
wait(5)
gui.Q5.Visible = false
gui.Story.Visible = true
wait(15)
if player then 
game:GetService("TeleportService"):TeleportToSpawnByName(73690355, "SpawnLocation", player) 
end

0
Interesting. Stravellia 0 — 10y
0
Also just a note, this script is just a shorter rendition of yours above, using a for loop to reduce the number of times you loop the 'Q' gui. I guess TeleportService works in a LocalScript. Dummiez 360 — 10y
0
Wow! This really works! I now just have to fix the orientation of the gui's, and then find some way to get rid of the very short white flash between GUI's. Stravellia 0 — 10y
Ad
Log in to vote
1
Answered by
AxeOfMen 434 Moderation Voter
10 years ago

The problem is that you are acting on the game.StarterGui rather than the player.PlayerGui. So everywhere in your script where you write game.StarterGui.ScreenGui.XYZ.Visible = true/false change it to player.PlayerGui.ScreenGui.XYZ.Visible = true/false

[Edit]

IntellectualBeing's idea will make your code simpler, but it won't fix the problem you are having. When you modify the object that exists in game.StarterGui it will affect the object that is given to players when they spawn. You must modify the object that exists in the player's PlayerGui or the modifications will not affect the player.

0
I'll try Intellectual's idea first, then if that doesn't work out, I'll try yours. Stravellia 0 — 10y
0
Due to time issues, I'm trying yours first. I did exactly what you told me. Replace tool for the win! Stravellia 0 — 10y
0
Believe it or not.. I think AxeOfMen helped me with this exact problem I had too! IntellectualBeing 430 — 10y

Answer this question