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

For i,v in ipairs script destroying all the children in torso? [SOLVED]

Asked by 6 years ago
Edited 6 years ago

I'm trying to :Destroy() all BodyGyro and BodyVelocity in the player's torso.

--Some variables to define the player and character

local Movers = char.Torso:GetChildren()
for i,v in pairs(Movers) do
    if v == "BodyGyro" or "BodyVelocity" then
        v:Destroy()
    end
end

but it destroys all the children in the torso.

1 answer

Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
6 years ago

The reason your script isn't working because you are trying to compare an object to a string, also in your case you can't do v==blah or blah you'd have to do v==blah or v==blah2. So let's fix this.

First Let's bring in the correct part of your script.

for i,v in pairs(char.Torso:GetChildren()) do

end

Now let's use the :IsA() function to check if the object we are on has a classname of either body gyro or body velocity and if so destroy

for i,v in pairs(char.Torso:GetChildren()) do
    if v:IsA("BodyGyro") or v:IsA("BodyVelocity") then
        v:Destroy()
    end
end
0
ok SmugNyan 24 — 6y
0
Yes. "BodyVelocity" in an if statement is always true, so it would always run. hiimgoodpack 2009 — 6y
0
@hiimgoodpack actually it would return false for an instance is not the same as a string. https://gyazo.com/2dfb535e5c0d2ef299f0113fe5546916 DanzLua 2879 — 6y
Ad

Answer this question