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

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

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

✓ Accepted answer

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

3 comments

0

ok

0

Yes. "BodyVelocity" in an if statement is always true, so it would always run.

0

@hiimgoodpack actually it would return false for an instance is not the same as a string. https://gyazo.com/2dfb535e5c0d2ef299f0113fe5546916

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