Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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?

4 comments

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.

0

Of course I will explain how everything works.

0

Oh! Sure! This'll be a lot of help for my Universe! Of course, it's based off of the Elder Scrolls.

0

I'll need to do research, looking into tables.

2 answers

✓ Accepted answer

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

3 comments

0

Interesting.

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.

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.

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.

3 comments

0

I'll try Intellectual's idea first, then if that doesn't work out, I'll try yours.

0

Due to time issues, I'm trying yours first. I did exactly what you told me. Replace tool for the win!

0

Believe it or not.. I think AxeOfMen helped me with this exact problem I had too!

This discussion is preserved as it was. New answers, comments, and votes are closed.