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

How would you go selecting certain parts of a model in a script ?

I was creating a tool, and i wanted to select certain parts of a model to make that, when i unequip it will wield onto your waist. Problem is that it turns the transparency of **EVERY part, i only want 2 parts to be opaque (A Union and a part) And not to show the grip (Handle). Any help would be really greatful ! :)

PS : You don't have to worry about the other stuff, since it works just fine. This is a server script and is located in the ServerScriptService, ask me if you don't understand.

local radio = game.ServerStorage.Radio ---- Variables 
local radio_c = radio:Clone() 
local c_kids = radio_c:GetChildren

game.Players.PlayerAdded:Connect(function(plr)          
	plr.CharacterAdded:Connect(function(char)
		local RightWaistAttachment = Instance.new("Attachment")
		RightWaistAttachment.Name = "RightWaistAttachment"
		RightWaistAttachment.Position = Vector3.new(0.8,-0.6,-0.5)
		RightWaistAttachment.Parent = char.Torso 
		local M6D = Instance.new("Motor6D")
		M6D.Name = "ToolGrip"
		M6D.Parent = char.Torso
		local Weld = Instance.new("Weld")
		Weld.Name = "Radio_Wield"
		Weld.Part0 = radio_c.PrimaryPart
		Weld.Part1 = char.Torso
		Weld.C0 = Weld.Part0.RightWaistAttachment.CFrame
		Weld.C1 = Weld.Part1.RightWaistAttachment.CFrame 
		Weld.Parent = Weld.Part0
		radio_c.Parent = workspace
		for k,Part in pairs(c_kids) do
			Part.Transparency = 1 
		end
	end)
end)

game.ReplicatedStorage.ConnectM6D.OnServerEvent:Connect(function(plr, location)

	local char = plr.Character
	char.Torso.ToolGrip.Part0 = char.Torso
	char.Torso.ToolGrip.Part1 = location
	for k,Part in pairs(c_kids) do ---This
		Part.Transparency = 1
		end  
end)

game.ReplicatedStorage.DisconnectM6D.OnServerEvent:Connect(function(plr)
	plr.Character.Torso.ToolGrip.Part1 = nil
	for k,Part in pairs(c_kids) do --- And this 
				Part.Transparency = 0 
	end 
end)

1 answer

✓ Accepted answer

This is how I would actually do it

First of all we are going to count howmany childrens are there. Then create 2 variables that returns random numbers.

local model = model
local totalPartCount = #model:GetChildren

local selectedPart1 = math.random(1, totalPartCount)
local selectedPart2 = math.random(1, totalPartCount) 

Just incase if the random numbers are the same we add a number to the other one. Indentions are also off.

if selectedPart2 == selectedPart1 then
selectedPart2 = selectedPart2 + 1
end

Next we set the part's transparency Please do note that I sort of forgot how to do this part here, but hopefully you get the idea, and I'm pretty much sure you can find the solution to it. Also you need to make the children named 1 - how many you habe. Of course this isn't really the best solution but hey

model[tostring(selectedPart1)].Transparency = 1
model[tostring(selectedPart2)].Transparency = 1 

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