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

Why does my script crash every time I test it out?

I have a script that creates a "ghost" of the character. It's kinda like a very short trail that is the player. Whenever I run it, it crashes. Why?

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		while true do
		wait(.1)
		local getd = char:GetDescendants()
		if char:FindFirstChild("Folder") then
			char.Folder:Destroy()
		end
		for i,v in pairs(getd) do
			if v.ClassName == "UnionOperation" or v.ClassName == "Part" then
				if v.Name ~= "Torso" or v.Name ~= "Middle" then
					local folder = Instance.new("Folder")
					local clone = v:Clone()
					folder.Parent = char
					folder.Name = "Folder"
					clone.Parent = folder
					clone.CanCollide = false
					clone.Anchored = true
					if clone.Name ~= "Head" then
						clone:ClearAllChildren()
					end
					clone.Name = "Ghost"
					if v.Name == "HumanoidRootPart" then
						v.BrickColor = char.Torso.BrickColor
					end
					if v:FindFirstChild("Weld") then
						v.Weld:Destroy()
					end
				end
			end
		end
		end
	end)
end)

1 comment

0

It might be because you are trying to perform many different operations in less than .1 seconds. Experiment with the wait time...

1 answer

Your script is most likely crashing due to you attempting to loop through all of the character's descendants and then trying to clone and change all of them instantly. I would, like pojoto said, suggest adding a wait() in your loop. Also, you're using a while true do loop with another loop embedded inside, with no wait time, while also constantly cloning a folder and then deleting it over and over again.

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