Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Cloning Character For 3D Model Gui Help?

Good afternoon,

I'm trying to clone the local player's character into a model inside ReplicatedStorage named "NPC." I can't seem to figure out what's wrong with it and the last lines following the function work perfectly. I am welcome to any ideas, suggestions and recommendations. Thank you, for your time.

local pl = game.Players.LocalPlayer 
	 
if pl and pl.Character then 
	local c = pl.Character
	c.Archivable = true
	local duplicate = c:clone()
	duplicate.Parent = game.ReplicatedStorage.NPC
end

game.Players.LocalPlayer.PlayerGui:WaitForChild('PlayerAppear').Enabled = true
game.Players.LocalPlayer.PlayerGui:WaitForChild('PlayerAppear'):WaitForChild('LocalScript').Disabled = false

1 comment

0

Oh, this is a LocalScript btw in the StarterPlayerScripts.

1 answer

Your problem here is that you're trying to clone and move something from the client. That is not possible. What you might want to consider is creating a RemoteEvent in Workspace and firing it to do the cloning work. So basically keep this in the LocalScript:

local pl = game.Players.LocalPlayer 

if pl and pl.Character then 
    local c = pl.Character
    workspace.RemoteEvent:FireServer(c) -- You can change "RemoteEvent" to whatever your RemoteEvent is called.
    c.Archivable = true
    local duplicate = c:clone()
    duplicate.Parent = game.ReplicatedStorage.NPC
end

game.Players.LocalPlayer.PlayerGui:WaitForChild('PlayerAppear').Enabled = true
game.Players.LocalPlayer.PlayerGui:WaitForChild('PlayerAppear'):WaitForChild('LocalScript').Disabled = false

Now put this inside a ServerScript in Workspace:

workspace.RemoteEvent.OnServerEvent:connect(function(c)
	c.Archivable = true
	local duplicate = c:clone() 
	duplicate.Parent = game.ReplicatedStorage.NPC
end)

Then everything should work as expected.

EDIT:

Since I'm pretty sure you cannot simply clone a player character try this inside the ServerScript:

workspace.RemoteEvent.OnServerEvent:connect(function(plr, c)
	local duplicate = Instance.new("Model")
	duplicate.Name = c.Name
	for _, v in pairs(c:GetChildren()) do
		v:Clone().Parent = duplicate
	end
    duplicate.Parent = game.ReplicatedStorage.NPC
end)

2 comments

0

connect is deprecated

0

Hey, @incapaz, may you elaborate on that? I never heard about connect being deprecated, but I was off Roblox for the last months, so I could've just missed it.

This discussion is preserved as it was. New answers, comments, and votes are closed.