Image pop-up feature in voting system not working

I’m trying to script a picture of a player’s head pop up in a viewport frame.

The problem is whenever I try this, my “newCharacter” is nil in the output.

Code in a local script located in the StarterGui I used to experiment my issue
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

while true do
	local newCharacter = character:Clone() -- equal to nil
	newCharacter.Parent = workspace
	newCharacter:MoveTo(character.PrimaryPart.Position + Vector3.new(0,10,0))
	task.wait(1)
end
Code in an if statement located in a local script in the StarterGui
		print(character)
		print("-------")
		local camera = Instance.new("Camera")
		local newVPF = VPF:Clone()
		local newCharacter = character:Clone()
		print(newCharacter)
		camera.CFrame = CFrame.lookAt(newCharacter:FindFirstChild("Head").Position + Vector3.new(0,0,2),newCharacter.Head.Position)
		newCharacter.Parent = newVPF
		newVPF.CurrentCamera = camera
		camera.Parent = newVPF
		newVPF.Parent = holder:FindFirstChild(stat).CharacterHold
		for i,v in newCharacter:GetDescendants() do if v:IsA("Script") or v:IsA("LocalScript") or v:IsA("ModuleScript") then v:Destroy() end end
Code on the server I tried to fix my issue
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		for i = 1,10 do
			local newCharacter = character:Clone()
			newCharacter.Parent = workspace -- newCharacter in output says nil on this line
			newCharacter:MoveTo(character.PrimaryPart.Position + Vector3.new(0,10,0))
		end
	end)
end)
2 Likes

Try changing your server sided script to this:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid") -- Wait for the character to load
		if character.PrimaryPart then -- Check if the PrimaryPart exists
			for i = 1, 10 do
				local newCharacter = character:Clone()
				newCharacter.Parent = workspace
				newCharacter:MoveTo(character.PrimaryPart.Position + Vector3.new(0, 10, 0))
			end
		end
	end)
end)
2 Likes

The character models have an Archivable property that is false by default. You have to enable it to true before you clone the character.

character.Archivable = true
local newCharacter = character:Clone()
-- Rest of code
2 Likes

It worked! I didn’t think there would be a time when I’d be actually using that property.

1 Like

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