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

Get player character and clone it?

Asked by 8 years ago

This is a script that is in a Model, it's supposed to get the player's character which is in a StringValue and clone it and put it in another model. However, line 11 / 12 throws an error. Does anyone know how do I get around or fix this?

01local eotd = game.ReplicatedStorage.EOTD
02 
03eotd.Changed:connect(function()
04    if eotd.Value ~= nil then
05        local model = script.Parent["Employee Of The Day"]
06        local player = game.Workspace:FindFirstChild(eotd.Value)
07        for i, v in pairs(model:GetChildren()) do
08            v:Destroy()
09        end
10        local character = game.Players[eotd.Value].Character
11        character:Clone().Parent = script.Parent["Employee Of The Day"]
12        print('NAC: Value changed')
13        model:WaitForChild('Humanoid').MaxHealth = 0
14        model.Humanoid.Health = 0
15        model.Health:Destroy()
View all 21 lines...
0
What error does it throw? buoyantair 123 — 8y
0
18:44:17.988 - Workspace.EOTD.Script:11: attempt to index a nil value 18:44:17.989 - Stack Begin 18:44:17.990 - Script 'Workspace.EOTD.Script', Line 11 18:44:17.991 - Stack End TheEpicCooldeal 12 — 8y
0
It may be that the player's character may not have loaded in time for when the script executed; you could use the "CharacterAdded" event which will yield until the player's character has loaded. :) TheeDeathCaster 2368 — 8y
0
Nope, that is not the problem. TheEpicCooldeal 12 — 8y

3 answers

Log in to vote
0
Answered by
Faunx -5
8 years ago
1local player = game.Players.LocalPlayer
2local A = player.Character:GetChildren()
3A:Clone()
4A.Humanoid:Destroy()
5A.Animate:Destroy()
6A.Parent = script.Parent:FindFirstChild("Employee Of The Day!")

Add in all the rest.

0
It's not a LocalScript. Thank you though. TheEpicCooldeal 12 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

local client=game.Players.LocalPlayer local it=Instance.new local mod=it("Model",workspace)

for _,v in pairs(client:GetChildren()) do v:Clone().Parent=mod end

Log in to vote
0
Answered by 7 years ago

You should turn the Archivable property of the model to true. If it is set false, then you cannot clone it.

Answer this question