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

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

Asked by 8 years ago

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?

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 :) User#11440 120 — 8y

1 answer

Log in to vote
2
Answered by 8 years ago

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!

0
Thank you for helping me, that worked! AtomicChocolate 35 — 8y
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. BlackJPI 2658 — 8y
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. Link150 1355 — 8y
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 User#11440 120 — 8y
Ad

Answer this question