generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: hat remove

Previous Thread :: Next Thread 
swimmaster07 is not online. swimmaster07
Joined: 08 Jun 2013
Total Posts: 1459
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
128Gigabytes is not online. 128Gigabytes
Joined: 17 Apr 2014
Total Posts: 3616
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 is not online. hkep
Joined: 19 Jul 2014
Total Posts: 550
21 Jan 2016 01:17 AM
getDescendants(instance.Parent)*
Report Abuse
bowlsroblox is not online. bowlsroblox
Joined: 03 Dec 2013
Total Posts: 133
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
bowlsroblox is not online. bowlsroblox
Joined: 03 Dec 2013
Total Posts: 133
21 Jan 2016 03:06 AM
This is the simplest one.


Bowlsroblox_Scripter
Report Abuse
128Gigabytes is not online. 128Gigabytes
Joined: 17 Apr 2014
Total Posts: 3616
21 Jan 2016 03:12 AM
It also doesn't search as deep.
Report Abuse
Froast is not online. 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
swimmaster07 is not online. swimmaster07
Joined: 08 Jun 2013
Total Posts: 1459
21 Jan 2016 08:19 AM
bowls I know i eventually figured this out myself!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image