So I was trying to make a clone of yourself if you click a button, but I get the error "Workspace.Part.ClickDetector.Script:8: attempt to index local 'clone' (a nil value)"
game.Players.PlayerAdded:Connect(function(player) local name = player.Name
script.Parent.MouseClick:connect(function() local x = workspace:FindFirstChild(name) print (x.Name) local clone = x:Clone() clone.Parent = game.Workspace end) end)
Use :GetService()
to retrieve the Players
Service
Use the CharacterAdded
Event of the Player Instance to get the model, rather than FindFirstChild()
game.Workspace
can be shortened to workspace
connect
is deprecated in favor of Connect
When the player's Character
is created, you can only :Clone()
it if its Archivable
property is manually set to true, since otherwise, as you've seen, the Instance's Clone function will return nil
game:GetService("Players").PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(x) x.Archivable = true script.Parent.MouseClick:Connect(function() local clone = x:Clone() clone.Parent = workspace end) end) end)