|
| 30 Jul 2017 06:09 PM |
I'd like to make a variable that selects all the parts in a player that plays in my single-player game. Eventually, I would like to use this variable in a function that changes the body part's reflectance or transparency upon touching an object. Here's what I have so far:
player = game.Players:FindFirstChild()
However, for some reason, this doesn't work! All help is appreciated.
***Our greatest fear should not be of failure but of succeeding at things in life that don't really matter.*** |
|
|
| Report Abuse |
|
|
Rinem
|
  |
| Joined: 05 Jan 2014 |
| Total Posts: 255 |
|
|
| 30 Jul 2017 06:16 PM |
I got you
Put this script in the brick that's gonna get touched to change that player's bodycolors/reflectance
script.Parent.Touched:Connect(function(part)
if part.Parent:FindFirstChild("Humanoid") then playerchildren = part.Parent:GetChildren() for i, v in pairs(playerchildren) do if v:IsA("Part") or v:IsA("MeshPart") or v:IsA("BasePart") then v.Reflectance = 1 --//Or v.BrickColor = BrickColor.new("Whatever color you want") or use a color3.new end end end)
dabbin' on the haters |
|
|
| Report Abuse |
|
|
Scriptos
|
  |
| Joined: 17 Jun 2008 |
| Total Posts: 2900 |
|
|
| 30 Jul 2017 06:19 PM |
function getAllParts(object, existing) local list = existing or {}; for i,v in ipairs(object:GetChildren()) do if (v:IsA("BasePart")) then table.insert(list, v); end; getAllParts(v, list); end return list end;
function setPropertyOfParts(list, property, value) for i,v in ipairs(list) do pcall(function() v[property] = value; end) end end;
script.Parent.Touched:connect(function(part) if (part.Parent:FindFirstChild("Humanoid")) then local characterModel = part.Parent; setPropertyOfParts(getAllParts(characterModel), 'Transparency', .5); end end);
This code will work with hats as well, or anything that is hidden inside something else within the character model. |
|
|
| Report Abuse |
|
|
Rinem
|
  |
| Joined: 05 Jan 2014 |
| Total Posts: 255 |
|
|
| 30 Jul 2017 06:21 PM |
Aaaand Scriptos takes the cake!
dabbin' on the haters |
|
|
| Report Abuse |
|
|
Scriptos
|
  |
| Joined: 17 Jun 2008 |
| Total Posts: 2900 |
|
|
| 30 Jul 2017 06:25 PM |
| @Rinem; Sorry, I just figured that it'd be more useful if it also affected parts that might be hidden within hats or other objects inside of the character. 😂 |
|
|
| Report Abuse |
|
|
|
| 30 Jul 2017 08:04 PM |
Thanks so much guys; I tested both and they work great!
***Our greatest fear should not be of failure but of succeeding at things in life that don't really matter.*** |
|
|
| Report Abuse |
|
|