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

how do i make my main menu reappear?

i resolved the issue from my last question, wherein the player wouldn't die after spawning in as an elk. however, i ran into a problem where i couldn't get the main menu to go away, then i figured it out by unchecking the "ResetonSpawn" box, but now it won't reappear when the player character dies.

here's my script:

local elk = game.ReplicatedStorage.animalsm.elkadm
local camsub = workspace.Camera.CameraSubject
local plr = game.Players

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.changechar:FireServer(game.ReplicatedStorage.animalsm.elkadm)
	camsub = elk.Humanoid
	script.Parent.Parent.Parent.Visible = false
end)

elk.Humanoid.Died:Connect(function()
		script.Parent.Parent.Parent.Visible = true
	end)

the script at the bottom is the one i tried to get it to reappear, but no dice.

1 comment

0

line 2 change workspace.Camera.CameraSubject to workspace.CurrentCamera.CameraSubject

1 answer

Problem

When a player dies all their GUIs get replaced, so when you do

script.Parent.Parent.Parent.Visible = true

It does this on the old GUI, but the new one comes right after replacing the old one.

Solution

I think the way to do this is to use the CharacterAdded event

LocalScript

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")


local elk = game.ReplicatedStorage.animalsm.elkadm
local Client = Players.LocalPlayer


Client.PlayerGui.IDK.MouseButton1Click:Connect(function()    
    ReplicatedStorage.changechar:FireServer(elk) -- You already had a variable for the argument you passed.
    camsub = elk.Humanoid
    script.Parent.Parent.Parent.Visible = false
end)


local function OnCharacterAdded()
   script.Parent.Parent.Parent.Visible = true
end)


Client.CharacterAdded:Connect(OnCharacterAdded)

Explanation

It's good to do

Client.CharacterAdded:Connect(OnCharacterAdded)

Why?

Because what you did was create a function every time(improving performance). This isn't useful in the code i gave you, but it can be in server scripts. I did this because I think it looks a lot more cleaner.

It's also good to use the method GetService() in cases where you re-name the service, but it's up to you.

I think it's better to define your GuiObjects from the player, but it's up to you.

Hopefully the code works because I wrote it all here.

If there's any problems or errors you can just comment on my answer.

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