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

Respawn menu won't close!?

Asked by 3 years ago
Edited 3 years ago

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

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

[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)
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 Sonnymacko 19 — 3y
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 Sonnymacko 19 — 3y
0
unfortunely, you have to use a local script to manage the gui closing. Gmorcad12345 434 — 3y
View all comments (10 more)
0
i edited my answer Gmorcad12345 434 — 3y
0
alright, thanks for sharing the explorer with me, I can help better now Gmorcad12345 434 — 3y
0
Oh dam. So how would i manage to respawn the player after they've clicked the button? Sonnymacko 19 — 3y
0
hold on, i'm editing my answer one more time Gmorcad12345 434 — 3y
0
alright, i'm done. Gmorcad12345 434 — 3y
0
Wow, thanks man this worked! It takes like two seconds to actually close the GUI is there a reason or fix for this? Sonnymacko 19 — 3y
0
you meant after you click respawn it takes 2 seconds to close? Gmorcad12345 434 — 3y
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! Gmorcad12345 434 — 3y
0
You can look in Players.RespawnTime. Maybe its set 2 seconds there Gmorcad12345 434 — 3y
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. Sonnymacko 19 — 3y
Ad

Answer this question