Attempt to index nil with 'Parent'

Hi, so basically I have a problem when I tries to clone the same player and change parent to workspace. The problem is the topic name.

Here’s my script:

shadowclone.OnServerEvent:Connect(function(plr, model, char)
	print("shadow clone script works")
	local charclone = workspace:FindFirstChild(char.Name):Clone()
	charclone.Parent = workspace
end)

Firstly, you can’t pass objects through as parameters, meaning model and char would be passed as either just their name or nil, I’m not quite sure. Secondly, passing the character as a parameter like this would be dangerous as an exploiter could pass their own model and clone it. Thirdly, if you already have the char there is no need to do char.Name.

Your script should look something like this with all of that taken into account:

shadowclone.OnServerEvent:Connect(function(player)

   local char = player.Character or player.CharacterAdded:Wait()
   local charClone = char:Clone()
   charClone.Parent = workspace

end)

This is my local script to fire shadow clone event.

local re = game.ReplicatedStorage.RemoteEvents
local shadowclone= re.ShadowClone
local plr = game.Players.LocalPlayer
local char = plr.Character
local uis = game:GetService("UserInputService")
local db = false

uis.InputBegan:Connect(function(key, chattin)
	if chattin then return end
	if db == false then
		if key.KeyCode == Enum.KeyCode.E then
		db = true
			shadowclone:FireServer(smokemodel, char)
			wait(2)
			db = false
		end
	end
end)

Please look at both scripts. And tell me what should I improve.

It’s still not working though. It keep saying this.

I see a few things that can be improved in this script. To begin with, you should replace wait with task.wait(), it’s basically just an improved version of it with more safety. The other issue is that you’re handling the debounce on the client, which means an exploiter can just bypass this and have no cooldowns. You can stop this by handling the cd on the server. Finally, you don’t need to do db == false. You can just do if not db then.

Apart from those issues and the unconventional variable names it looks alright. Also, because I removed the model parameter in the server script, you won’t have to pass it on the client, so you wont need to give any arguments.

The reason is the character is not set to archivable, meaning it can’t be cloned. You’ll have to toggle it on before you clone it and turn it off once you’re done with it.