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

How exactly do morphs work? And what is this 'i, b in pairs' function?

I have recently been trying to make a morph from scratch by dissecting lots of free model morphs to try and find out how they work. However I am getting stuck on a few things.

So far it seems they copy and paste parts of the morph model into the player who activates them, and the copy-pasted parts override the existing parts of said player. Is this correct or is it more complicated than that?

Another thing is the morph scripts I've been reading have a common occurrence of this 'for i,b in pairs () do' thingy, example here

	BodyParts = hit.Parent:GetChildren()
		for i,b in pairs(BodyParts) do
			if (b.className == "Humanoid") then
				CanMorph = true
			end

What is up with that?

1 answer

✓ Accepted answer

This script is literally, going through everything in the hit.Parent, and IF one of them is a Humanoid, CanMorph is true. Its to make sure whatever hit it, is an actual player, and not like a part, or union or w/e.


for i,v in pairs(hit.Parent:GetChildren()) do
	if v:IsA("Humanoid" then
	CanMorph = true
 end

 -- v is each part of (hit.Parent:GetChildren())
-- i is the number of 'things' found.

5 comments

0

So if I where to convert it into a GUI button I could ignore the pairs completely?

0

uhh, i guess so

0

Thanks, Connor!

0

no prob, accept my answer/thumbs up!

0

I don't have enough reputation to upvote :(

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