Menu code is not functioning properly and does not display any error messages

Hi!

I’m currently working on writing a LocalScript for my main menu. The goal is to display the player’s own avatar in the background, with the avatars of other players on the server visible behind it. To achieve this, I clone the character models from the original player character and then place them onto a part inside Workspace. However, I’m facing an issue where my code doesn’t seem to work, and I’m unable to determine the cause. It also doesn’t print out any error message.

This is my current code inside the localscript:

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local LocalCharacter = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()

local PlayerGui = script.Parent.Parent
local MainMenu = PlayerGui:WaitForChild("UI"):WaitForChild("MainMenu")

local camera = workspace.CurrentCamera

local LobbyCFrame = workspace:WaitForChild("Lobby"):WaitForChild("LobbySceneMenu"):WaitForChild("Cams"):WaitForChild("Cam").CFrame

local maxXRotation = 10
local maxYRotation = 10

local MenuCameraModule = require(game:GetService("ReplicatedStorage"):WaitForChild("GameLogic"):WaitForChild("MainMenuSystems"):WaitForChild("Modules"):WaitForChild("MenuCamera"))

local menuCamera = MenuCameraModule.new(camera, LobbyCFrame, maxXRotation, maxYRotation)

local ui_background_blur = game:GetService("Lighting"):FindFirstChild("UIBlur")

local function EnableBlur()
	if not ui_background_blur then
		ui_background_blur = Instance.new("BlurEffect")
		ui_background_blur.Name = "UIBlur"
		ui_background_blur.Size = 11
		ui_background_blur.Enabled = false
		ui_background_blur.Parent = game:GetService("Lighting")
	end
	ui_background_blur.Enabled = true
end

local function DisableBlur()
	if ui_background_blur then
		ui_background_blur.Enabled = false
	end
end

local function UpdatePlayerPositions(playerCount)
	local existingCharacters = workspace:GetChildren()

	local function CleanupPlayerCharacters()
		for _, existingCharacter in ipairs(existingCharacters) do
			if existingCharacter:IsA("Model") and existingCharacter.Name == "Clone" and existingCharacter:FindFirstChild("Humanoid") and existingCharacter.Humanoid.Health == 0 then
				existingCharacter:Destroy()
			end
		end
	end

	local AnimationId = "14020964902"

	CleanupPlayerCharacters()

	for i, player in pairs(Players:GetPlayers()) do
		if player ~= LocalPlayer then 
			local character = player.Character or player.CharacterAdded:Wait()
			local rigName = "R_" .. tostring(playerCount - i) 
			local rigsObject = workspace:FindFirstChild("Rigs")
			
			if rigsObject then
				local rig = rigsObject:FindFirstChild(rigName)
				if rig then
					local rigCFrame = rig.CFrame

					local clone = character:Clone()
					clone:SetPrimaryPartCFrame(rigCFrame)
					clone.Parent = workspace
					clone.Name = character.Name .. "_CLONE"

					local humanoid = clone:FindFirstChildOfClass("Humanoid")
					if humanoid and AnimationId ~= "" then
						local animation = Instance.new("Animation")
						animation.AnimationId = "rbxassetid://" .. AnimationId
						humanoid:LoadAnimation(animation):Play()
					end
				else
					warn(rigName .. " not found in Rigs")
				end
			else
				warn("Rigs not found in workspace")
			end
		end
	end
	
	local clientRig = workspace:WaitForChild("Lobby"):WaitForChild("LobbySceneMenu"):WaitForChild("Rigs"):WaitForChild("R_Client")
	local client = game:GetService("Players").LocalPlayer
	local clientCharacter = client.Character
	local clientCharacterClone = clientCharacter:Clone()
	clientCharacterClone.Parent = workspace
	
	clientCharacterClone:WaitForChild("HumanoidRootPart").Anchored = true
	
	if clientRig then
		local rigCFrame = clientRig.CFrame
		
		local function setPrimaryCFrameOfCharacter()
			if clientCharacterClone.PrimaryPart then
				clientCharacterClone:SetPrimaryPartCFrame(clientRig.CFrame)
			else
				clientCharacterClone.PrimaryPart = clientCharacterClone:WaitForChild("HumanoidRootPart")
				setPrimaryCFrameOfCharacter()
			end
		end
		
		setPrimaryCFrameOfCharacter()
		
		clientCharacterClone:WaitForChild("HumanoidRootPart").Anchored = false
		
		local humanoid = clientCharacterClone:FindFirstChildOfClass("Humanoid")
		if humanoid and AnimationId ~= "" then
			local animation = Instance.new("Animation")
			animation.AnimationId = "rbxassetid://" .. AnimationId
			humanoid:LoadAnimation(animation):Play()
		end
	else
		warn(clientRig.Name .. " not found in Rigs")
	end
end

local function WaitForCharacter()
	LocalPlayer.CharacterAdded:Wait()
	LocalCharacter = LocalPlayer.Character
	UpdatePlayerPositions(#game:GetService("Players"):GetPlayers())
end

if MainMenu.Enabled then
	menuCamera:Enable()
	EnableBlur()
end

MainMenu:GetPropertyChangedSignal("Enabled"):Connect(function()
	if MainMenu.Enabled then
		menuCamera:Enable()
		EnableBlur()
	else
		menuCamera:Disable()
		DisableBlur()
	end
end)

if LocalCharacter then
	UpdatePlayerPositions(#game:GetService("Players"):GetPlayers())
else
	WaitForCharacter()
end
2 Likes

Maybe you should use ViewPortFrame

2 Likes

I thought about that too, though it doesn’t look that good because of the lighting.

2 Likes

Alright found the problem. I forgot to set Archivable to true while cloning the character.

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