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

Morph acting out and i need help?

heres the script that makes the morph what it is:

function onTouch(part) 
local human = part.Parent:findFirstChild("Humanoid") 
if human ~= nil then 
part.Parent:findFirstChild("Head").BrickColor = BrickColor.new(125)
part.Parent:findFirstChild("Head").Transparency = 0
part.Parent:findFirstChild("Torso").BrickColor = BrickColor.new(1)
part.Parent:findFirstChild("Torso").Transparency = 1
part.Parent:findFirstChild("Left Arm").BrickColor = BrickColor.new(1)
part.Parent:findFirstChild("``Left Arm").Transparency = 1
part.Parent:findFirstChild("Right Arm").BrickColor = BrickColor.new(1)
part.Parent:findFirstChild("Right Arm").Transparency = 1
part.Parent:findFirstChild("Left Leg").BrickColor = BrickColor.new(1)
part.Parent:findFirstChild("Left Leg").CanCollide = true
part.Parent:findFirstChild("Left Leg").Transparency = 1
part.Parent:findFirstChild("Right Leg").BrickColor = BrickColor.new(1)
part.Parent:findFirstChild("Right Leg").CanCollide = true
part.Parent:findFirstChild("Right Leg").Transparency = 1
end 
end 
script.Parent.Touched:connect(onTouch)]

1 comment

0

Check line 20.

1 answer

There is a lot of deprecated code here, so I'm kind of assuming that you didn't write this. First of all (no pun intended), use FindFirstChild(), not findFirstChild(). Also, use Connect rather than connect. Another thing, you shouldn't be checking if there is a Humanoid inside of the parent of what was hit. You should probably use GetPlayerFromCharacter() and check if the result isn't nil. This way, you'll know for a fact that the Instance that collided with the part is either a child of the player's character itself. Next, why do you have a closing square bracket (This thing: ]) at the end of your code? Finally, check out this super duper cool link: https://www.robloxdev.com/articles/Writing-Clean-Code.

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