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

Respawn menu won't close!?

Hello, I've been trying to make a menu that displays when the player dies. When the player dies a menu will display with a respawn button but nothing happens when they press the button. Also, there is no error in the output. My code:

LOCAL Script 1(MenuOpener)

local Players = game:GetService("Players") 
local menu = script.Parent -- Gets the Menu
local player = Players.LocalPlayer
local character = player.Character 


character:WaitForChild("Humanoid").Died:Connect(function()
	menu.Visible = true 
end)

Script 2(RespawnHandler) l~~~~~~~~~~~~~~~~~ local RespawnButton = script.parent game.Players.CharacterAutoLoads = false

local menu = script.Parent local Players = game:GetService("Players") local player = Players.LocalPlayer RespawnButton.MouseButton1Click:Connect(function() --Below does not work! if player then menu.Visible = false player:LoadCharacter() end end)


1 answer

✓ Accepted answer

[EDIT2] Your RespawnHandler script should be replaced with a LocalScript Because, MouseButton1Click can ONLY be detected by a LocalScript ! Since you need to use LoadCharacter , prepare a RemoteEvent named anything you like and insert it in ReplicatedStorage. In this case, I'm naming my RemoteEvent "RemoteEvent" which is the default name

This script below is CURRENTLY your script which should be replaced by a LocalScript. So yes, the thing below should be inserted in a localscript

local RespawnButton = script.parent
--game.Players.CharacterAutoLoads = false , you can't put this in a local script so I'm currently commenting it out
local menu = script.Parent 
local Players = game:GetService("Players") 
local player = Players.LocalPlayer 
local RemoteEvent = game.ReplicatedStorage.RemoteEvent --new variable
RespawnButton.MouseButton1Click:Connect(function() 
    if player then 
        menu.Visible = false 
        RemoteEvent:FireServer(game.Players.LocalPlayer,game.Players.LocalPlayer)
    
    end 
end)

In another normal script in ServerScriptService:

local RemoteEvent = game.ReplicatedStorage.RemoteEvent 
RemoteEvent.OnServerEvent:Connect(function(player)
    game.Players.CharacterAutoLoads = false
    player:LoadCharacter()
end)

14 comments

0

Sadly, this doesn't work. My script isn't a LocalScript because i need to use player:LoadCharacter() Which can't be used in a LocalScript if I'm correct

0

Sadly, this doesn't work. My script isn't a LocalScript because i need to use player:LoadCharacter() Which can't be used in a LocalScript if I'm correct

0

unfortunely, you have to use a local script to manage the gui closing.

0

i edited my answer

0

alright, thanks for sharing the explorer with me, I can help better now

0

Oh dam. So how would i manage to respawn the player after they've clicked the button?

0

hold on, i'm editing my answer one more time

0

alright, i'm done.

0

Wow, thanks man this worked! It takes like two seconds to actually close the GUI is there a reason or fix for this?

0

you meant after you click respawn it takes 2 seconds to close?

0

well there isn't really a reason, as there isn't a wait(2) anywhere along the script. Also please accept the solution since it worked for you!

0

You can look in Players.RespawnTime. Maybe its set 2 seconds there

0

Oh it is, is there a way to stop it from doing that? If i set it to zero it will just keep doing it every second.

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