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

Why does my Screen GUI keep showing whenever I reset?

I've tried:

function onClick()
	if script.Parent.Visible == true then
		script.Parent.Visible = false
	end
	if script.Parent.Parent.TextLabel.Visible == true then
		script.Parent.Parent.TextLabel.Visible = false
	end
end

script.Parent.MouseButton1Click:connect(onClick)

So my problem is that whenever I reset it shows up again and I only want it to show up once when you first enter the game. Also Im kind of new to scripting so explaining would be a help but isn't necessary.

3 answers

When a player's character dies, their PlayerGui and Backpack are cleared and replaced with whatever is currently in the place's StarterGui and StarterPack, aswell as what's in the player's StarterGear.

If you wish to only give the GUI to the player when they first join the game, you should put the GUI into ServerStorage and write a script which clones the GUI into any new players, using the PlayerAdded event.

For example,

local ServerStorage = game:GetService("ServerStorage")

game.Players.PlayerAdded:connect(function(Player)
	local PlayerGui = Player:WaitForChild("PlayerGui")
	ServerStorage.TheGUI:Clone().Parent = PlayerGui
end)

The above script clones an instance, from ServerStorage, named 'TheGUI' and places it into the player's PlayerGui. We are using WaitForChild since when the PlayerAdded event is fired, the player's PlayerGui may not exist yet. WaitForChild combats this issue.

1 comment

0

Okay so first is this a local script or just a regular script? And second where does the script/localscript placed? Thanks this seems promising :D

In order to do this, we will have to declare the event PlayerAdded to detect when someone enters the game.

local gui = script.ScreenGui -- Location of GUI

game.Players.PlayerAdded:connect(function(player)
gui:Clone().Parent = player.PlayerGui
end)

This is the script that I am using at the moment you could remove the filtering enabled if you are not using it. I hope this helps:-

function onHumanoidDied(property, plr)
	
	plrGui = plr.PlayerGui:FindFirstChild("ScreenGui")
	
	if plr~= nil and plrGui~=nil then	
		plr.PlayerGui.ScreenGui:Destroy()
	end
	
end

function onPlayerRespawn(property, plr)
	
        while plr and plr.Parent do
            	if plr.Character then break end
            wait(1)
        end

        if not (plr and plr.Parent) then return end

   wait(1)
	if game.Workspace.FilteringEnabled then
		game.Workspace.FilteringEnabled = false
		wait(1)
		Workspace.ScreenGui:Clone().Parent = plr.PlayerGui
		game.Workspace.FilteringEnabled = true
	else
		game.Workspace.FilteringEnabled = true
	end
    
end

function onPlayerEntered(plr)

		while plr and plr.Parent do
            if plr.Character then break end
            wait(1)
		        end
       if not (plr and plr.Parent) then return end

		wait(1)
		game.Workspace.ScreenGui:Clone().Parent = plr.PlayerGui
		
		plr.CharacterRemoving:connect(function(property) onHumanoidDied(property, plr) end)
        plr.CharacterAdded:connect(function(property) onPlayerRespawn(property, plr) end)

end
game.Players.PlayerAdded:connect(onPlayerEntered)

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