The bug is probably because you didn’t use “CharacterAdded” on your script. Because CharacterAdded event can be used to reinitialize the menu when the player respawns.
Another solution is probably by using “repeat wait() until Players.LocalPlayer.Character” to ensure the character is fully loaded before attempting to reinitialize the menu.
well reused a bit of code from elsewhere in my game but still nothing
local function onCharacterAdded(character)
MainMenu.PlayButton.TextButton.MouseButton1Click:Connect(function()
print("hello")
TankRemoteEvents.SpawnTank:FireServer("Leopard2A7")
end)
MainMenu.TanksButton.TextButton.MouseButton1Click:Connect(function()
CamControls.TankSelectCam(3)
end)
TankOptions.Back.TextButton.MouseButton1Click:Connect(function()
CamControls.MainMenuCam(3)
end)
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
test:Disconnect()
end)
end
test = Player.CharacterAdded:Connect(onCharacterAdded)
if Player.Character then
onCharacterAdded(Player.Character)
end
Oh wait, I probably found the solution. If it doesn’t work again, I can’t find any solution anymore. Try to use this script (there’s table.insert for the fireServer) :
local UserInputService = game:GetService("UserInputService")
local ContextActionService = game:GetService("ContextActionService")
local CamControls = require(script.Parent.CamControls)
local TankRemoteEvents = game.ReplicatedStorage.TankRemoteEvents
local DataStoreRemoteEvents = game.ReplicatedStorage.DataStoreRemoteEvents
local Configs = game.Players.LocalPlayer.PlayerGui.Configuration
local Mouse = game.Players.LocalPlayer:GetMouse()
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local connections = {}
local function initializeMainMenu()
local MainMenu = game.Workspace.Other.MainMenu.CamPart:WaitForChild("MainMenu").MainMenu
local TankOptions = game.Workspace.Other.MainMenu.TankSelect:WaitForChild("TankOptions").Options
DataStoreRemoteEvents.GetPlayerStats.OnClientEvent:Connect(function(PlayerStats)
MainMenu.PlayerInfo.PlayerLevel.Text = "Level: " .. PlayerStats.Level
MainMenu.PlayerInfo.PlayerCash.Text = PlayerStats.Cash .. "$"
MainMenu.PlayerInfo.XP.XPAmount.Text = PlayerStats.XP .. "/" .. PlayerStats.XPNeeded
MainMenu.PlayerInfo.XP.Bar.Size = UDim2.fromScale(math.clamp(PlayerStats.XP / PlayerStats.XPNeeded, 0, 1), 1)
end)
table.insert(connections, MainMenu.PlayButton.TextButton.MouseButton1Click:Connect(function()
print("hello")
TankRemoteEvents.SpawnTank:FireServer("Leopard2A7")
end))
table.insert(connections, MainMenu.TanksButton.TextButton.MouseButton1Click:Connect(function()
CamControls.TankSelectCam(3)
end))
table.insert(connections, TankOptions.Back.TextButton.MouseButton1Click:Connect(function()
CamControls.MainMenuCam(3)
end))
end
local function onCharacterAdded(character)
character:WaitForChild("Humanoid")
for _, connection in ipairs(connections) do
connection:Disconnect()
end
connections = {}
initializeMainMenu()
character.Humanoid.Died:Connect(function()
for _, connection in ipairs(connections) do
connection:Disconnect()
end
connections = {}
end)
end
Player.CharacterAdded:Connect(onCharacterAdded)
if Player.Character then
onCharacterAdded(Player.Character)
else
initializeMainMenu()
end`