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
What error does it throw?
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
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. :)
Nope, that is not the problem.