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

Get player character and clone it?

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)

4 comments

0

What error does it throw?

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

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. :)

0

Nope, that is not the problem.

3 answers

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.

1 comment

0

It's not a LocalScript. Thank you though.

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

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

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