How can I create a template for each player in the game?

Hello, So I’m currently trying to make a script that will loop through all of the players in the game and create a template for each player on the server so I want every player in the game to see all of the players that are still alive kind of like the game Among Us I tried this but it creates a template for the local player here is my script:

I have this function on a module scirpt:
function module.AddTemplate()
	for i, v in pairs(game.Players:GetPlayers()) do
		local character = v.Character
		if character:FindFirstChild('InGame') then
			game.ReplicatedStorage.AddTemplate:FireAllClients(v)
		end
	end
end
On a local script:
game.ReplicatedStorage.AddTemplate.OnClientEvent:Connect(function(player)
	local template = script.Parent:FindFirstChild('Template'):Clone()
	template.Parent = script.Parent
	template.Name = player.Name
	template.Visible = true
	template.PlayerName.Text = player.Name
end)

And Also I call the function every second on my round script.

Thank you!

1 Like

Use this function

local Players = game:GetService(“Players”)

local function onCharacterAdded(character)
	print(character.Name .. " has spawned")
end
 
local function onCharacterRemoving(character)
	print(character.Name .. " is despawning")
end
 
local function onPlayerAdded(player)
	player.CharacterAdded:Connect(onCharacterAdded)
	player.CharacterRemoving:Connect(onCharacterRemoving)
end
 
Players.PlayerAdded:Connect(onPlayerAdded)
2 Likes

This creates a copy of the player and destroys the copy when the player dies

local Players = game:GetService("Players")
 
local function onCharacterAdded(character)
	print(character.Name .. " has spawned")
	
	character.Archivable = true
    local Copie = character:Clone()
	Copie.Parent = game.Workspace		
				
    character.Archivable = false	
end
 
local function onCharacterRemoving(character)
	print(character.Name .. " is despawning")
	
	local Removal = game.Workspace:FindFirstChild("character.Name")
	if Removal then
	   Removal:Destroy()
	end
	
end
 
local function onPlayerAdded(player)
	player.CharacterAdded:Connect(onCharacterAdded)
	player.CharacterRemoving:Connect(onCharacterRemoving)
end
 
Players.PlayerAdded:Connect(onPlayerAdded)
2 Likes