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

How do I get a model's children?

Asked by 5 years ago

So I was trying to get a model's children and make the anchor property to false. Could some one help?




local model = script.Parent local noob = script.Parent:WaitForChild("Ragdoll") local victory = game.Workspace:WaitForChild("Now thats a victory royale") local victory_royal = game.ServerStorage:WaitForChild("Part") while script.Parent == workspace do local part = noob:GetChildren() if part:IsA("Part") then part.Anchored = false wait(1) victory:Play() local clonedSign = victory_royal:Clone() clonedSign.Parent = workspace end end

3 answers

Log in to vote
0
Answered by 5 years ago
for i,v in pairs(put here your model) do
if v:IsA("Part") then
v.Anchored = false
end
end
Ad
Log in to vote
0
Answered by 5 years ago

All I'm going to do is show you how to unanchor all parts in a model.

Its some simple code using: for i,v in pairs() do.

What you do is this:

for i,v in pairs(noob:GetChildren()) do
    if v:IsA("Part") then
        v.Anchored = false
    end
end

--Rest of code--

Do not put your sound playing into the for i,v loop. That will play the sound once for each part inside of "noob" and the same with the sign. It will clone the sign for each part in the "noob".

Hope this helps!

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

what you can do is use a pairs() loop, to loop through the models children,

now since we have to use :GetChildren(), it returns a table of all the models children, so we can write a loop

for _,child in pairs(MODELHERE:GetChildren()) do -- This Will loop through the models children
    if child:IsA("BasePart") then -- Check If it is a base part (wedge,part,cylinder etc...)
        child.Anchored = false -- Un anchor the part!
    end
end

but its not done, under neath that code, add this to make the sound play:

local victory = workspace:WaitForChild("Now Thats A Victory Royale") -- wait for the victory sound
local victory_royal = game.ServerStorage:WaitForChild("Part") -- get the sign
victory:Play() -- play the sound
local cloned_sign = victory_royal:Clone() -- clone the sign
cloned_sign.Parent = workspace-- parent it to workspace!

So All in all it looks like...

for _,child in pairs(MODELHERE:GetChildren()) do -- This Will loop through the models children
    if child:IsA("BasePart") then -- Check If it is a base part (wedge,part,cylinder etc...)
        child.Anchored = false -- Un anchor the part!
    end
end
local victory = workspace:WaitForChild("Now Thats A Victory Royale")
local victory_royal = game.ServerStorage:WaitForChild("Part")
victory:Play()
local cloned_sign = victory_royal:Clone()
cloned_sign.Parent = workspace

Hope This Helps! -Kriscross102

Answer this question