Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how do i make my main menu reappear?

Asked by 2 years ago

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.

0
line 2 change workspace.Camera.CameraSubject to workspace.CurrentCamera.CameraSubject MarkedTomato 810 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

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.

Ad

Answer this question