So, I’m trying to achieve this effect that the player joins the game, sees the main menu, and when they hit play they no longer see the menu in fact its not even in the starter gui. However, I’m running into a lot of issues with this design I have and I feel it could be do to a major design flaw instead of logic errors as I’m getting to warnings/errors.
Here’s my code:
ReplicatedFirst = game:GetService("ReplicatedFirst")
ReplicatedStorage = game:GetService("ReplicatedStorage")
local needsMainMenu = script.Parent:WaitForChild("NeedsMainMenu")
local MasterControl = require(game.Players.LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule"):WaitForChild("ControlModule"))
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
-- Player must get a menu when they join or when they choose to respawn and go back to main menu
local function checkNewSpawn(char)
local hrp = char:WaitForChild("HumanoidRootPart", 3)
if (hrp) then
if needsMainMenu.Value then
ReplicatedStorage:WaitForChild("MoveCameraMain"):Fire(Player) -- Bindable Event in Replicated Storage
MasterControl:Disable() --disables movement
local mainMenu = ReplicatedFirst:WaitForChild("MainMenu")
local playerCopy = mainMenu:Clone()
playerCopy.Parent = game.Players.LocalPlayer.PlayerGui
else
MasterControl:Enable() --enables movement
end
end
end
if Player.Character then
print("hi")
checkNewSpawn(Player.Character)
end
game.Players.LocalPlayer.CharacterAdded:Connect(function(char)
print("bye")
checkNewSpawn(char)
end)
This works about 75% of the time and the other 25% of the time the player spawns in with movement enabled and not moved to the appropriate camera object (but they do get the main menu gui)