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 7 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?

local eotd = game.ReplicatedStorage.EOTD

eotd.Changed:connect(function()
    if eotd.Value ~= nil then
        local model = script.Parent["Employee Of The Day"]
        local player = game.Workspace:FindFirstChild(eotd.Value)
        for i, v in pairs(model:GetChildren()) do
            v:Destroy()
        end
        local character = game.Players[eotd.Value].Character
        character:Clone().Parent = script.Parent["Employee Of The Day"]
        print('NAC: Value changed')
        model:WaitForChild('Humanoid').MaxHealth = 0
        model.Humanoid.Health = 0
        model.Health:Destroy()
    for i, v in pairs(model:GetChildren()) do
        v.Anchored = true
        v.CanCollide = true
    end
    end
end)
0
What error does it throw? buoyantair 123 — 7y
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 — 7y
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 — 7y
0
Nope, that is not the problem. TheEpicCooldeal 12 — 7y

3 answers

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

Add in all the rest.

0
It's not a LocalScript. Thank you though. TheEpicCooldeal 12 — 7y
Ad
Log in to vote
0
Answered by 7 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 6 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