So I've made a menu that players will only see upon joining the game. The local script that handles all the buttons and frames and behaviors are inside the gui named "menu".
Upon joining the game, "menu" is cloned and put inside a player's playergui as intended. The menu works as intended up until I try to respawn the player using loadcharacter(). I do not use loadcharacter() in the local script.
I use loadcharacter() in a normal script called "Loader" in the serverscriptservice which handles the fire events such as teaming. The teaming part of the menu works fine. But when I click team, my player is teamed and reloaded, but
as they spawn the playergui is cleared, which is what I intended to do. The "menu" should be gone after the player is reloaded.
The problem is I get an error from the local script inside the "menu" for indexing a parent which is the parent of the script, the "menu". I don't understand why it's even indexing the parent when the entire menu should be gone.
I've tried safely indexing everything, even deleting the menu before the player is reloaded.
Here is the error 06:24:54.987 - ARVN is not a valid member of Frame
ARVN is a button, and the frame is the "menu" that holds everything including other buttons and the local script that is erroring.
I've tested this in game and it only happens in game, I think because loadcharacter() doesn't work as it should in studio anyways (it doesn't clear the gui when a character respawns)
So if you could help me understand why it is erroring?
Here's a snippit of the script
local Workspace = game:GetService("Workspace") local Players = game:GetService("Players") local Lighting = game:GetService("Lighting") local Replicated = game:GetService("ReplicatedStorage") local Storage = game:GetService("ServerStorage") local Debris = game:GetService("Debris") local RunService = game:GetService("RunService") local events = game.ReplicatedStorage.Events local client_Event = events.Menu Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) if not player:FindFirstChild("Teamed") then local menu = game.ServerStorage.Guis.Menu:Clone() menu.Parent = player.PlayerGui end end) end) game.ReplicatedStorage.Events.Menu.Menu_Event.OnServerEvent:connect(function(player, message, color) if message == "ARVN" then player.TeamColor =BrickColor.new(color) player.PlayerGui.Menu:Destroy() player:LoadCharacter() end if message == "VietCong" then player.TeamColor =BrickColor.new(color) player.PlayerGui.Menu:Destroy() player:LoadCharacter() end if message == "NVA" then player.TeamColor =BrickColor.new(color) player.PlayerGui.Menu:Destroy() player:LoadCharacter() end if message == "USM" then player.TeamColor =BrickColor.new(color) player.PlayerGui.Menu:Destroy() player:LoadCharacter() end if message == "CIV" then player.TeamColor =BrickColor.new(color) player.PlayerGui.Menu:Destroy() player:LoadCharacter() end end)
here's a piece of the local script
local player = game.Players.LocalPlayer local camera = game.Workspace.CurrentCamera local play_Button = script.Parent.Menu.Play local customize_Button = script.Parent.Menu.Customize local store_Button = script.Parent.Menu.Store local help_Button = script.Parent.Menu.Help local Team_Select = script.Parent:WaitForChild('Team_Select') while not player do wait() end play_Button.MouseButton1Click:connect(function() script.Parent.Menu.Visible = false script.Parent.Team_Select.Visible = true end) Team_Select.ARVN.MouseButton1Click:connect(function() game.ReplicatedStorage.Events.Menu.Menu_Event:FireServer("ARVN", "New Yeller") end) Team_Select.NLF.MouseButton1Click:connect(function() game.ReplicatedStorage.Events.Menu.Menu_Event:FireServer("VietCong", "Steel blue") end) Team_Select.PAVN.MouseButton1Click:connect(function() game.ReplicatedStorage.Events.Menu.Menu_Event:FireServer("NVA", "Bright red") end) Team_Select.USM.MouseButton1Click:connect(function() game.ReplicatedStorage.Events.Menu.Menu_Event:FireServer("USM", "Earth green") end) Team_Select.CIV.MouseButton1Click:connect(function() game.ReplicatedStorage.Events.Menu.Menu_Event:FireServer("CIV", "Bright blue") end)
Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) if not player:FindFirstChild("Teamed") then local menu = game.ServerStorage.Guis.Menu:Clone() menu.Parent = player.PlayerGui local teamValue = Instance.new("BoolValue", player) teamValue.Name = "Teamed" end end) end)