Guis visibility set to false after respawning

Hi, I made a kill script for a game though after respawning all the guis visibilities are set to false.

Kill part script:

local Tower = game.Workspace:WaitForChild("Tower")

for i, v in pairs (Tower:GetDescendants()) do
	
	if v:IsA("BoolValue") and v.Name == "Touched" then
		
		v.Parent.Touched:Connect(function(Hit)
			
			if Hit.Parent:FindFirstChild("Humanoid") then
				
				Hit.Parent.Humanoid.MaxHealth = 0
				Hit.Parent.Humanoid.Health = 0
			end
		end)
	end
end

Script that makes guis visible when a player joins the game:

local Height = script.Parent:WaitForChild("Frame")
local Timer = script.Parent.Parent.Timer:WaitForChild("Timer")
local CandyDisplay = script.Parent.Parent:WaitForChild("Display"):WaitForChild("CandyDisplay")

Height.Visible = true
Timer.Visible = true
CandyDisplay.Visible = true

To fix this, I would use a CharacterAdded function. Is the script that makes the guis visible when the player joins in a LocalScript or just a Script?

The script that controls the visibilities is a local script.

Okay, so what I would do is inside of that LocalScript, type the following:

local Player = game.PlayersLocalPlayer
Player.CharacterAdded:Connect(function()
   Height.Visible = true
   Timer.Visible = true
   CandyDisplay.Visible = true
end)

Try that and let me know if that works or not.

1 Like

Alright I tested this function but when I join the game none of the guis are visible now.

Alright, then one more thing to do. Use this code:

local Player = game.PlayersLocalPlayer
local Height = script.Parent:WaitForChild("Frame")
local Timer = script.Parent.Parent.Timer:WaitForChild("Timer")
local CandyDisplay = script.Parent.Parent:WaitForChild("Display"):WaitForChild("CandyDisplay")
game.Players.PlayerAdded:Connect(function()
 Height.Visible = true
   Timer.Visible = true
   CandyDisplay.Visible = true
end)
Player.CharacterAdded:Connect(function()
   Height.Visible = true
   Timer.Visible = true
   CandyDisplay.Visible = true
end)

That should work now.

1 Like

You might want to set property ResetOnSpawn of the ScreenGui to true.

2 Likes

Alright thanks the guis stay visible now.

1 Like