Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Jexpler 63
6 years ago

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?

01game.Players.PlayerAdded:Connect(function(plr)
02    plr.CharacterAdded:Connect(function(char)
03        while true do
04        wait(.1)
05        local getd = char:GetDescendants()
06        if char:FindFirstChild("Folder") then
07            char.Folder:Destroy()
08        end
09        for i,v in pairs(getd) do
10            if v.ClassName == "UnionOperation" or v.ClassName == "Part" then
11                if v.Name ~= "Torso" or v.Name ~= "Middle" then
12                    local folder = Instance.new("Folder")
13                    local clone = v:Clone()
14                    folder.Parent = char
15                    folder.Name = "Folder"
View all 34 lines...
0
It might be because you are trying to perform many different operations in less than .1 seconds. Experiment with the wait time... Pojoto 329 — 6y

1 answer

Log in to vote
2
Answered by 6 years ago

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.

Ad

Answer this question