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

Why Does This Only Work Partialy?

I am trying to make it so when a player dies, they turn into 50 small bricks. The script clears all the body parts, but does not create any parts. My Script

debounce = false
while true do
	if script.Parent.Humanoid.Health == 0 and debounce == false then
		debounce = true
		
		local pos = script.Parent:FindFirstChild("Torso").Position
		local child = script.Parent:ClearAllChildren()
		
		local model = Instance.new("Model")
		model.Name = "temp"
		model.Parent = script.Parent
		

		for i=1, 50, 1 do
			local b = Instance.new("Part")
			b.BrickColor = BrickColor.new(1012)
			b.Reflectance = 1
			b.Transparency = 0.7
			b.CanCollide = false
			b.Size = Vector3.new(1,1,1)
			b.TopSurface = Enum.SurfaceType.Smooth
			b.BottomSurface = Enum.SurfaceType.Smooth
			b.Position = pos
			b.Parent = model
			wait(0.01)
		end
		
		wait(2)
		
		model:ClearAllChildren()
		
	end
	wait()
end

it is in the players character.

1 answer

It's because you deleted the script in line 7. Have the script check what its deleting before it deletes it.

debounce = false
while true do
    if script.Parent.Humanoid.Health == 0 and debounce == false then
        debounce = true

        local pos = script.Parent:FindFirstChild("Torso").Position
        for _,v in pairs(script.Parent:GetChildren()) do --Loop through all objects of the parent.
             if v ~= script then --If the object isn't the script, then continue on.
                   v:Destroy() --Destroy the part.
             end
       end

        local model = Instance.new("Model")
        model.Name = "temp"
        model.Parent = script.Parent

        for i=1, 50, 1 do
            local b = Instance.new("Part")
            b.BrickColor = BrickColor.new(1012)
            b.Reflectance = 1
            b.Transparency = 0.7
            b.CanCollide = false
            b.Size = Vector3.new(1,1,1)
            b.TopSurface = Enum.SurfaceType.Smooth
            b.BottomSurface = Enum.SurfaceType.Smooth
            b.Position = pos
            b.Parent = model
            wait(0.01)
        end

        wait(2)

        model:ClearAllChildren()

    end
    wait()
end

Hope this helps!

1 comment

0

Thanks and it did help but i ditched the loop and just used a repeat wait() until script.Parent.Health == 0

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