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

Morph acting out and i need help?

Asked by 5 years ago
Edited 5 years ago

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)]
0
Check line 20. User#19524 175 — 5y

1 answer

Log in to vote
0
Answered by
lunatic5 409 Moderation Voter
5 years ago

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.

Ad

Answer this question