Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Cloning Character For 3D Model Gui Help?

Asked by 5 years ago

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
0
Oh, this is a LocalScript btw in the StarterPlayerScripts. sparkevin 36 — 5y

1 answer

Log in to vote
1
Answered by
Wutras 294 Moderation Voter
5 years ago
Edited 5 years ago

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)
0
connect is deprecated User#19524 175 — 5y
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. Wutras 294 — 5y
Ad

Answer this question