I have a model which is made of grouped parts, and for each part, I've scripted them so that when touched, it will disappear. My problem is, I can't seem to script the whole model so that when you touch one part, the rest will disappear with it. Could someone help me? I really need this whole model to disappear and reappear.
Since a group is a collection of parts, you will need to loop through the parts and manually change their transparency to 1. For this example, we will be using the "for i,v in pairs" loop (https://developer.roblox.com/articles/For-Loops). First, we will need to get the parts in the model for the loop to cycle through. We can the parts (otherwise known as "Children") of a model by using a built-in roblox feature ":GetChildren" (https://developer.roblox.com/api-reference/function/Instance/GetChildren). After that, we will need to create the variables and assign one the table of parts. In all, it should look like this.
local model = game.Workspace.Model --Change this to the location of your model local childrenInModel = model:GetChildren()
Next, we will need to add the "for i,v in pairs" loop. Now that we have table of parts in the model, we can go on and set the loop. It should look similar to this.
for i,v in pairs(childrenInModel) do --Check if part end
Since anything besides parts can be in a model, we will need to check whether the part is an actual part. We can do this by adding another roblox built-in feature ":IsA" (https://developer.roblox.com/api-reference/function/Instance/IsA). Basically, this feature checks whether the part is what you want to check it is. So we would ":IsA" like this.
for i,v in pairs(childrenInModel) do if v:IsA("Part") then --Change Transparency end end
Finally, we will need to change the transparency of the object to make it "disappear". This is as easy as simply writing "v.Transparency = 1". So in the end, your code should look similar to this.
local model = game.Workspace.Model --Change this to the location of your model local childrenInModel = model:GetChildren() for i,v in pairs(childrenInModel) do if v:IsA("Part") then v.Transparency = 1 end end
When you say 'Disappear' do you mean go completely transparent and have the CanCollide field turned off, or do you mean destroyed?
You could try something along the lines of this and modify to what you want:
-- Script (on server, inside part inside model) script.Parent.Touched:Connect(function() for i,v in next, script.Parent.Parent:GetDescendants() do v:Destroy() end end)
A simple explanation: when the parent of the script (in this case the part inside the model) is touched, loop through the parent's parent (in this case, the model) and destroy every object inside of the model.