Workspace.Sbeve.Script:15: attempt to index nil with 'Clone'

(ENGLISH IS MY SECOND LANGUAGE, I MIGHT HAVE GRAMMAR PROBLEMS)

So, i just wanted to recreate sbeve from Slap Battles, so i made a cloning script. I tried using script.Parent:Clone(), the model is archivable.

  1. What do you want to achieve? Keep it simple and clear! So i want to fix script.Parent:Clone() error.

  2. What is the issue? Include screenshots / videos if possible! Issue is Workspace.Sbeve.Script:15: attempt to index nil with ‘Clone’ error

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? Not really, just looked up at one page (Attempt to index nil with ‘clone’) and it all about one tool.

script.Parent.Torso.Touched:Connect(function(bas)
	local par = bas.Parent
	local hum = par:FindFirstChild("Humanoid")
	if hum then
		if par:FindFirstChild("Sbevee") == nil then
			local plr = game.Players:GetPlayerFromCharacter(par)
			print(plr)
			if plr ~= nil then
				game.SoundService.useful.cartoon_pop:Play()
				for i, scr in pairs(script.Parent:GetChildren()) do
					if scr:IsA("Script") then
						script:Destroy()
					end
				end
				local clone = script.Parent:Clone()
				clone.Name = "Sbeve"
				clone.Parent = workspace
				plr.Character = clone
			end
		end
	end
end)
1 Like
for i, scr in pairs(script.Parent:GetChildren()) do
    if scr:IsA("Script") then
        script:Destroy()
    end
end

The above loop causes your script to get destroyed. When you destroy an instance, its “Parent” property is locked and set to nil. This is the source of your error. Move the loop past your cloning logic

The error is clearly not coming from the same script anymore:

image

Sorry, i just edited wrong script and tested another sbeve
(its working)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.