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

How do I make the parameter be for the player who triggered the event?

My code will turn you into a noob, but my code doesn't do so when it runs.

script.Parent.Touched:connect(function(player)
		player.Parent.Torso.BrickColor = BrickColor.new("Really Blue")
		player.Parent.RightLeg.BrickColor = BrickColor.new("Forest Green")
		player.Parent.LeftLeg.BrickColor = BrickColor.new("Forest Green")
                player.Parent.RightArm.BrickColor = BrickColor.new("New Yeller")
		player.Parent.LeftArm.BrickColor = BrickColor.new("New Yeller")
		player.Parent.Head.BrickColor = BrickColor.new("New Yeller")
		player.Parent.Shirt.Destroy()
		player.Parent.Pants.Destroy()
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?

1 comment

0

If you could remember to accept my answer, it helps a lot. The accept button is under my name by my answer. Thank you :)

1 answer

✓ Accepted answer

It's Right Leg, with a space.

Along with the arms and the rest of the legs.

In order to fix this, you have to use FindFirstChild.

Here's the following script,

script.Parent.Touched:connect(function(player)
        player.Parent.Torso.BrickColor = BrickColor.new("Really Blue")
        player.Parent:FindFirstChild("Right Leg").BrickColor = BrickColor.new("Forest Green")
        player.Parent:FindFirstChild("Left Leg").BrickColor = BrickColor.new("Forest Green")
        player.Parent:FindFirstChild("Right Arm").BrickColor = BrickColor.new("New Yeller")
        player.Parent:FindFirstChild("Left Arm").BrickColor = BrickColor.new("New Yeller")
        player.Parent.Head.BrickColor = BrickColor.new("New Yeller")
        player.Parent.Shirt.Destroy()
        player.Parent.Pants.Destroy()
end)

I would also suggest using an if statement to make sure that what touched the brick is a Humanoid.

script.Parent.Touched:connect(function(player)
	if not player.Parent:FindFirstChild("Humanoid") then return end
        player.Parent.Torso.BrickColor = BrickColor.new("Really Blue")
        player.Parent:FindFirstChild("Right Leg").BrickColor = BrickColor.new("Forest Green")
        player.Parent:FindFirstChild("Left Leg").BrickColor = BrickColor.new("Forest Green")
        player.Parent:FindFirstChild("Right Arm").BrickColor = BrickColor.new("New Yeller")
        player.Parent:FindFirstChild("Left Arm").BrickColor = BrickColor.new("New Yeller")
        player.Parent.Head.BrickColor = BrickColor.new("New Yeller")
        player.Parent.Shirt.Destroy()
        player.Parent.Pants.Destroy()
end)

I hope I helped!

Good Luck!

4 comments

0

Thank you for helping me, that worked!

1

Instead of FindFirstChild, you could also use square brackets to index the objects, e.g. player.Parent["Right Arm"].BrickColor.  However, both ways work.

0

What if the player got his legs or arms blown off for some reason? Always make sure FindFirstChild actually returns something before setting an object's properties.

0

People tell me to keep it simple, then I get yelled at for not making the best script in the whole world. He said it fixed the problem, so eh :P

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