|
| 20 Jan 2016 09:01 PM |
So my player is wearing a bandana hat right now and I have a script that removes my players bandana when I touch a part...
local part = script.Parent
part.Touched:connect(function(hit) local hat = hit.Parent:WaitForChild("Bandana") hat:Destroy() end)
How would I change the script so that I dont need to give the specific name of the hat? How would I make a script that when the part is stepped on it removes any hats a player is wearing?
|
|
|
| Report Abuse |
|
|
|
| 20 Jan 2016 09:07 PM |
local function getDescendants(instance) local output, x = instance:getChildren(), 1 while (output[x]) do for _, child in next, output[x]:getChildren() do table.insert(output, child) end x = (x + 1) end return output; end
script.Parent.Touched:connect(function(instance) for _, child in next, getDescendants(instance) do if (child:isA("Hat")) then child:destroy() end end end |
|
|
| Report Abuse |
|
|
hkep
|
  |
| Joined: 19 Jul 2014 |
| Total Posts: 550 |
|
|
| 21 Jan 2016 01:17 AM |
getDescendants(instance.Parent)*
|
|
|
| Report Abuse |
|
|
|
| 21 Jan 2016 03:05 AM |
script.Parent.Touched:connect(function(hit) if hit.Parent then for i, v in pairs(hit.Parent) do if v:IsA("Hat") then v:remove() end end end end)
Bowlsroblox_Scripter |
|
|
| Report Abuse |
|
|
|
| 21 Jan 2016 03:06 AM |
This is the simplest one.
Bowlsroblox_Scripter |
|
|
| Report Abuse |
|
|
|
| 21 Jan 2016 03:12 AM |
| It also doesn't search as deep. |
|
|
| Report Abuse |
|
|
Froast
|
  |
| Joined: 12 Mar 2009 |
| Total Posts: 3134 |
|
|
| 21 Jan 2016 04:37 AM |
| It doesn't have to, hats will always be directly in a player's character (unless changed by the server, which was not specified here). Sometime's scripts are made overly complicated even though they only need to do a specific thing. |
|
|
| Report Abuse |
|
|
|
| 21 Jan 2016 08:19 AM |
| bowls I know i eventually figured this out myself! |
|
|
| Report Abuse |
|
|