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) ~~~~~~~~~~~~~~~~~
[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)