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 » Scripting Helpers
Home Search
 

How to hat script

Previous Thread :: Next Thread 
thetacah is not online. thetacah
Joined: 18 Jan 2013
Total Posts: 16026
16 Feb 2014 08:35 PM
Hey ATR! I'm making this simple thread to teach you guys how to make a Hat script where if you take your hat off, we will DESTROY it!

To get a script click on workspace, then view-BasicObjects-Script

Double click the script to open it up.


First off, you will make a .ChildAdded Event. We will want to put an argument in thefunction too. The arugment will be the child
2 ways to start this:

1.
function ChildaDDED(Child) --This is a basic function

2.

game.Workspace.ChildAdded:connect(function(Child) --This is a anonymous function.

After you created your function, you are gonna want to make an if statement. Our if statement is gonna use a method called IsA. This is a way to identify things like hats and such. At the end of your if statement, you will put a then. so, what this does is it's gonna run what we will put under the code if it's a hat. Note:If statements and functions take ends.

1.function ChildaDDED(Child) --This is a basic function
if Child:IsA("Hat") then
2.
game.Workspace.ChildAdded:connect(function(Child) --This is a anonymous function.
if Child:IsA("Hat") then
Next up, we will attempt to Destroy the hat by using a Method called Destroy(). I forgot to mention that when you take you're hat off, it goes to the workspace which is why we use the event on Workspace.
1.function ChildaDDED(Child) --This is a basic function
if Child:IsA("Hat") then
Child:Destroy()
2.
game.Workspace.ChildAdded:connect(function(Child) --This is a anonymous function.
if Child:IsA("Hat") then
Child:Destroy()
Now, we will want to put some ends. To end the anonymous function, you have to put 'end)'. you put a ')' because you never closed it. You will also want to add a normal end to end the if statement. With the basic function, simply apply to ends.
1.function ChildaDDED(Child) --This is a basic function
if Child:IsA("Hat") then
Child:Destroy()
end
end
2.
game.Workspace.ChildAdded:connect(function(Child) --This is a anonymous function.
if Child:IsA("Hat") then
Child:Destroy()
end
end)
Now, our Anonymous function is done, but not the basic one. We haven't added an event yet, so to connect our event, we will have to do'game.Workspace.ChildAdded:connect(functionnamehere)'. So, that's a connection line for if you didn't use the anonymous function.
1.function ChildaDDED(Child) --This is a basic function
if Child:IsA("Hat") then
Child:Destroy()
end
end
game.Workspace.ChildAdded:connect(ChildaDDED)
Thanks! Have a very good day!
Report Abuse
thetacah is not online. thetacah
Joined: 18 Jan 2013
Total Posts: 16026
16 Feb 2014 08:36 PM
I made so many spelling mistakes...whatever.
Report Abuse
Aerospaceman is not online. Aerospaceman
Joined: 05 Mar 2011
Total Posts: 9881
16 Feb 2014 08:37 PM
As long as there are no mistakes in the script lel.
Report Abuse
thetacah is not online. thetacah
Joined: 18 Jan 2013
Total Posts: 16026
16 Feb 2014 08:39 PM
@Aero, I tested the anonymous script and it worked, and I don't see why the basic one would have an error.
Report Abuse
thetacah is not online. thetacah
Joined: 18 Jan 2013
Total Posts: 16026
16 Feb 2014 08:41 PM
Ok, I just tested both of the scripts, and they both work:)
Report Abuse
thetacah is not online. thetacah
Joined: 18 Jan 2013
Total Posts: 16026
16 Feb 2014 08:42 PM
Bum[.
Report Abuse
thetacah is not online. thetacah
Joined: 18 Jan 2013
Total Posts: 16026
16 Feb 2014 08:45 PM
Bump*
Report Abuse
thetacah is not online. thetacah
Joined: 18 Jan 2013
Total Posts: 16026
16 Feb 2014 08:48 PM
No-One freaking replying, I want feedback.
Report Abuse
MaskedGamers is not online. MaskedGamers
Joined: 15 Feb 2014
Total Posts: 144
16 Feb 2014 08:49 PM
So you could use this to add a hat to a player if they are chosen as it? Mmmm?
Of course, a different script but yeah.. this would apply.. right?
Report Abuse
MaskedGamers is not online. MaskedGamers
Joined: 15 Feb 2014
Total Posts: 144
16 Feb 2014 08:50 PM
Oh and good script. Very well explained.
Report Abuse
thetacah is not online. thetacah
Joined: 18 Jan 2013
Total Posts: 16026
16 Feb 2014 08:54 PM
@Masked, What do you mean? How to pick a random player and to give them a hat?
Report Abuse
MaskedGamers is not online. MaskedGamers
Joined: 15 Feb 2014
Total Posts: 144
16 Feb 2014 08:56 PM
Yeah. Like when people are chosen on hide and seek.. but it gives them a hat. I could just use the freeze tag script for an example.. I guess.
Report Abuse
thetacah is not online. thetacah
Joined: 18 Jan 2013
Total Posts: 16026
16 Feb 2014 09:05 PM
To choose a random Player you would do this

local Players = Game.Players:GetPlayers()
local Chosen2 = math.random(1, #Players)


You would probably then want to clone a the hat you want into the player's Character.


To get the proper hat in storage, you will have to add a Hat Instance and simply add a Part named 'Handle' and then put a mesh inside of it. Find the hats mesh ID and insert it to the mesh.

Then you would want to clone it into chosen2's character.


http://wiki.roblox.com/index.php?title=API:Instance/Clone

Of course, you would need to add some things, but that's sort liket he base.
Report Abuse
ExpIoders is not online. ExpIoders
Joined: 25 Aug 2013
Total Posts: 7859
16 Feb 2014 09:07 PM
Mods are gonna delete this because it's not "ROBLEECKS RELEETD" even though it is

Nice walkthrough though
Report Abuse
thetacah is not online. thetacah
Joined: 18 Jan 2013
Total Posts: 16026
17 Feb 2014 04:21 PM
This is Roblox related...
Report Abuse
Greenhouses is not online. Greenhouses
Joined: 22 Dec 2013
Total Posts: 9985
17 Feb 2014 04:22 PM
Tracking! :)
Report Abuse
thetacah is not online. thetacah
Joined: 18 Jan 2013
Total Posts: 16026
25 Feb 2014 07:00 PM
Bump. I will be bumping this often:O
Report Abuse
ayub32 is not online. ayub32
Joined: 27 Dec 2009
Total Posts: 485
25 Feb 2014 07:02 PM
Nice tutorial, learned a few things.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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