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

How Do I Set The Transparency Of The Parts Inside A Model To 1?

Iv'e begun creating a mine but I don't want to destroy the model straight after its stood one, I want to let the sound finish playing before I Destroy the mine. I thought of making the parts transparent until the sound is finished and then destroying the model as a whole.

local de = false -- Debounce

local mine = script.Parent.Parent -- Defining the model

local descendants = mine:GetDescendants() -- I could use GetChildren

script.Parent.Touched:Connect(function(hit)
	local h = hit.Parent:FindFirstChild("Humanoid")
	if h ~= nil and de == false then
		de = true
		local e = Instance.new("Explosion")
		e.Parent = script.Parent
		e.Position = script.Parent.Position
		script.Explosion:Play()
		for i=1,#descendants do
			local descendant = descendants[i]
			if descendant:IsA("BasePart") then
				descendant.Transparency = 1	
		wait(3.4)
		script.Parent.Parent:Destroy()
		end
	end
end

Any help would be appreciated

2 answers

✓ Accepted answer
local de = false -- Debounce

local mine = script.Parent.Parent-- Defining the model

local children = mine:GetChildren() -- GetChildren() is another way of getting all parts in a model.

script.Parent.Touched:Connect(function(hit)
    local h = hit.Parent:FindFirstChild("Humanoid")
    if h ~= nil and de == false then
        de = true
        local e = Instance.new("Explosion")
        e.Parent = script.Parent
        e.Position = script.Parent.Position
        script.Explosion:Play()
        for _, v in pairs(children) do -- Using a for loop to get the objects inside the object.
        if v:IsA("Part") or v:IsA("UnionOperation") or v:IsA("MeshPart") then
            v.Transparency = 1
        wait(3.4)
        script.Parent.Parent:Destroy()
       	 end
    	end
	end
end)

3 comments

0

He already had a For Loop. He just needed to change "BasePart" to "Part"

0

Still, tried that out with his and my script and wont get rid of all objects.

0

Part is a descendant of BasePart, so it does not matter

use loops like

this

for i, v in pairs(game.Workspace.Model:GetChildren()) do
         -- your code
end

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