My code will turn you into a noob, but my code doesn't do so when it runs.
01 | script.Parent.Touched:connect( function (player) |
02 | player.Parent.Torso.BrickColor = BrickColor.new( "Really Blue" ) |
03 | player.Parent.RightLeg.BrickColor = BrickColor.new( "Forest Green" ) |
04 | player.Parent.LeftLeg.BrickColor = BrickColor.new( "Forest Green" ) |
05 | player.Parent.RightArm.BrickColor = BrickColor.new( "New Yeller" ) |
06 | player.Parent.LeftArm.BrickColor = BrickColor.new( "New Yeller" ) |
07 | player.Parent.Head.BrickColor = BrickColor.new( "New Yeller" ) |
08 | player.Parent.Shirt.Destroy() |
09 | player.Parent.Pants.Destroy() |
10 | end ) |
Output result: "18:29:22.524 - RightLeg is not a valid member of Model 18:29:22.528 - Script 'Workspace.Noobifier.Head.Script', Line 3 18:29:22.531 - Stack End"
So how do I make the parameter be for the player who touched the part?
In order to fix this, you have to use FindFirstChild
.
Here's the following script,
01 | script.Parent.Touched:connect( function (player) |
02 | player.Parent.Torso.BrickColor = BrickColor.new( "Really Blue" ) |
03 | player.Parent:FindFirstChild( "Right Leg" ).BrickColor = BrickColor.new( "Forest Green" ) |
04 | player.Parent:FindFirstChild( "Left Leg" ).BrickColor = BrickColor.new( "Forest Green" ) |
05 | player.Parent:FindFirstChild( "Right Arm" ).BrickColor = BrickColor.new( "New Yeller" ) |
06 | player.Parent:FindFirstChild( "Left Arm" ).BrickColor = BrickColor.new( "New Yeller" ) |
07 | player.Parent.Head.BrickColor = BrickColor.new( "New Yeller" ) |
08 | player.Parent.Shirt.Destroy() |
09 | player.Parent.Pants.Destroy() |
10 | end ) |
I would also suggest using an if statement to make sure that what touched the brick is a Humanoid.
01 | script.Parent.Touched:connect( function (player) |
02 | if not player.Parent:FindFirstChild( "Humanoid" ) then return end |
03 | player.Parent.Torso.BrickColor = BrickColor.new( "Really Blue" ) |
04 | player.Parent:FindFirstChild( "Right Leg" ).BrickColor = BrickColor.new( "Forest Green" ) |
05 | player.Parent:FindFirstChild( "Left Leg" ).BrickColor = BrickColor.new( "Forest Green" ) |
06 | player.Parent:FindFirstChild( "Right Arm" ).BrickColor = BrickColor.new( "New Yeller" ) |
07 | player.Parent:FindFirstChild( "Left Arm" ).BrickColor = BrickColor.new( "New Yeller" ) |
08 | player.Parent.Head.BrickColor = BrickColor.new( "New Yeller" ) |
09 | player.Parent.Shirt.Destroy() |
10 | player.Parent.Pants.Destroy() |
11 | end ) |
I hope I helped!
Good Luck!