Need help with LoadCharacter issue in main menu

So I’ve recently been making a main menu system for my combat styled game and I don’t want the player to spawn until they click play, so what would one do? LoadCharacter of course! There is only one problem, when I press play, it loads fine, yet the camera goes to the void instead of onto the player. So any ideas?

Here’s both the scripts I’m using:

Localscript - In the gui in replicated storage

local Player = game.Players.LocalPlayer
local Character = Player.Character
local Camera = workspace.CurrentCamera
local Mouse = game.Players.LocalPlayer:GetMouse()
local DefaultCFrame = workspace.CameraPart.CFrame
local Scale = 160
local InMenu = true

local UI = script.Parent
local Buttons = UI.Buttons
local FadeFrame = UI:WaitForChild('FadeFrame')
local SpawnText = UI:WaitForChild('FadeFrame').Spawn
local MenuItems = UI:WaitForChild('Buttons')
local PlayButton = MenuItems:WaitForChild('Play')
local ModesButton = MenuItems:WaitForChild('Play')
local Modes = MenuItems:WaitForChild('Play')

local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(
	1,
	Enum.EasingStyle.Quart,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

local tweenInfo2 = TweenInfo.new(
	0.8,
	Enum.EasingStyle.Quart,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)
local tween = tweenService:Create(FadeFrame, tweenInfo, {Transparency = 0})
local tweenText = tweenService:Create(SpawnText, tweenInfo, {TextTransparency = 0})

local tween2 = tweenService:Create(FadeFrame, tweenInfo2, {Transparency = 1})
local tweenText2 = tweenService:Create(SpawnText, tweenInfo2, {TextTransparency = 1})

repeat wait()
	Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable

game:GetService("RunService").Heartbeat:Connect(function()
	Camera.Focus = DefaultCFrame
	local Center = Vector2.new(Camera.ViewportSize.X/2, Camera.ViewportSize.Y/2)
	local MoveVector = Vector3.new((Mouse.X-Center.X)/Scale, -(Mouse.Y-Center.Y)/Scale, 0)
	Camera.CFrame = DefaultCFrame * CFrame.Angles(math.rad(MoveVector.X), math.rad(MoveVector.Y), math.rad(MoveVector.Z))
	Camera.FieldOfView = 83
end)

Camera.CFrame = workspace.CameraPart.CFrame

PlayButton.MouseButton1Click:Connect(function()
	if InMenu then
	InMenu = false
		tween:Play()
		tweenText:Play()
		wait(5)
		game.ReplicatedStorage.LoadChar:FireServer()
		tween2:Play()
		tweenText2:Play()
		task.wait()
		Camera.CameraType = Enum.CameraType.Custom
		Camera.CameraSubject = Player.Character
	end
end)

Serverscript - In ServerScriptService

game.Players.PlayerAdded:Connect(function(Plr)
	game.ReplicatedStorage.Spawn.Parent = Plr:WaitForChild("PlayerGui")
end)

local Camera = workspace.CurrentCamera
	
local characterLoader = game.ReplicatedStorage:WaitForChild("LoadChar")
local function loadCharacter(client)
	if client then
		if client.Character ~= nil then print(client.Name .. " already has character loaded, reloading")
		else print(client.Name .. " had no character loaded, loading their character now!")
			client:LoadCharacter()
		end
	end
	characterLoader.OnServerEvent:connect(loadCharacter)
end

When I playtest the player won’t spawn and there is no errors in the console.

2 Likes

In your LocalScript, the reason why the camera does not go onto the player is because you are not able to set the CameraSubject to a Character model, you have to set the CameraSubject to a body part within the character (humanoid is default).

In your server script, you called the OnServerEvent within the ‘loadCharacter’ function, which is likely why the player isn’t spawning. Move the OnServerEvent code line outside of the ‘loadCharacter’ function.

Yes, but now the player spawns in and the gui is still on the screen, and the camera is stuck. You solved my requested problem though, thanks!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.