Gui not deleting

Ive been doing a game when you join, there is a 30 second timer and then the game starts. The timer is a screen gui. After 30 seconds, i wrote that it is going to destroy its self. After 30 seconds, it destroys its self like mentioned, the gui isnt in StarterGui anymore, but the timer stays on the screen even if it was deleted. After that an other gui is supposed to appear, but it doesnt appear for some reason. If you could help, I would appreciate it. Thanks

local StarterGui = game:GetService("StarterGui")
local CountdownGui = StarterGui.CountdownGui

local time = 30  
for i = 1, 30 do
wait(1) 
time = time - 1 
	script.Parent.Text = "Match starting in: "..tostring(time) 
	
end 

script.Parent.Text = "Starting Match..."
wait(1)
script.Parent.Text = "Choosing Teams..."
game.ServerScriptService.TeamChoosing.Enabled = true
wait(1)
CountdownGui:Destroy()
print("CountdownGui deleted from StarterGui")
2 Likes

You need to get the Gui from the PlayerGui, not StarterGui.

local CountdownGui = game.Players.LocalPlayer.PlayerGui.CountdownGui
3 Likes

Where is the script located? If its located directly inside the Gui, reference it using script.Parent instead:

local CountdownGui = script.Parent

Whats happening is that you’re referencing the gui in StarterGui and not the one that was cloned and placed into the Player’s PlayerGui

2 Likes

Capture23

2 Likes

Here is the script

local StarterGui = game:GetService("StarterGui")
local CountdownGui = StarterGui.CountdownGui

local time = 30  
for i = 1, 30 do
wait(1) 
time = time - 1 
	script.Parent.Text = "Match starting in: "..tostring(time) 
	
end 

script.Parent.Text = "Starting Match..."
wait(1)
script.Parent.Text = "Choosing Teams..."
game.ServerScriptService.TeamChoosing.Enabled = true
StarterGui.Teams.Enabled = true
wait(0.5)
CountdownGui:Destroy()
print("CountdownGui deleted from StarterGui")
2 Likes

I dont know what to do, could you help?

as he said change the second line to :

local CountdownGui = game.Players.LocalPlayer.PlayerGui.CountdownGui
--or
local CountdownGui = script.Parent.Parent
2 Likes
--Appropriate reference
local CountdownGui = script.Parent.Parent

local time = 30  
for i = 1, 30 do
wait(1) 
time = time - 1 
	script.Parent.Text = "Match starting in: "..tostring(time) 
	
end 

script.Parent.Text = "Starting Match..."
wait(1)
script.Parent.Text = "Choosing Teams..."
game.ServerScriptService.TeamChoosing.Enabled = true
StarterGui.Teams.Enabled = true
wait(0.5)
CountdownGui:Destroy()
print("CountdownGui deleted from StarterGui")

You were referencing the Gui within StarterGui. That Gui never moves and is cloned into every Player’s PlayerGui.

2 Likes

The script doesnt work at all now.



local StarterGui = game:GetService("StarterGui")
--local CountdownGui = StarterGui.CountdownGui
local CountdownGui = game.Players.LocalPlayer.PlayerGui.CountdownGui

local time = 30  
for i = 1, 30 do
wait(1) 
time = time - 1 
	script.Parent.Text = "Match starting in: "..tostring(time) 
	
end 

script.Parent.Text = "Starting Match..."
wait(1)
script.Parent.Text = "Choosing Teams..."
game.ServerScriptService.TeamChoosing.Enabled = true
StarterGui.Teams.Enabled = true
wait(0.5)

CountdownGui:Destroy()
print("CountdownGui deleted from StarterGui")
1 Like

Any errors printing in Output?

2 Likes

Nvm I see your issue, if you’re using a normal Script instead of a LocalScript then LocalPlayer wont exist since the code is Server Side.

2 Likes

Not sure it has anything to do with your issue, but why are you trying to access ServerScriptService, from a local client script?

Though that might not give an error, I don’t feel like it will achieve what you think it will.

2 Likes

If i put the script in a local script, i get this error now
TeamChoosing is not a valid member of ServerScriptService “ServerScriptService” - Client - LocalScript:16

1 Like

Because a LocalScript can’t access anything within ServerScriptService.

2 Likes

So what do i do now to fix this. The i need that line, so i could enable the team choosing process. The script would get enabled and then you would be assigned to a random team. Is it possible to maybe put a RemoteEvent?

1 Like

local CountdownGui = script.Parent.Parent
Just reference the Gui properly in the Script (Server-Side) instead of trying to access LocalPlayer

2 Likes

Yes, you will need a remote event to tell the server to enable the team choosing process.

1 Like

I tried to put a remote event days ago, but i never was able to get it to work. Could you help me do it?

Let me type something up as an example.

1 Like

i think i did it, let me test it.

1 Like