|
| 26 Jun 2016 03:29 PM |
Today ima show you people how to do a simple and advanced Key Press Event This is very helpful because it helps you to do many things in your game like equipping tools,opening and closing things,spawning items and more.. Ima do a simple Key Press Event with an Example.
1.Add a tool to Workspace 2.Add a script 3.In that script type
game.Players.LocalPlayer
tool = script.Parent
tool.Equipped:connect(function(mouse)
mouse.KeyDown:connect(function(key) if key == "q" then print(You Pressed q) local speedboost = 1.25 end end
If we test it in ROBLOX studio,if the player has the tool in thier hand and presses q,the player will get a speedboost,their current speed will be 17.25.The Normal Speed in Roblox is 16. |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 26 Jun 2016 03:30 PM |
DO NOT USE THE ABOVE EXAMPLES ^
KeyDown/KeyUp are deprecated. Use the UserInputService instead: http://wiki.roblox.com/?title=API:Class/UserInputService
|
|
|
| Report Abuse |
|
|
|
| 26 Jun 2016 03:30 PM |
| Actually you forgot to put quotes around that printed string |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 26 Jun 2016 03:31 PM |
you don't need quotes or parenthesis, you can use apostrophes
|
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 26 Jun 2016 03:31 PM |
Oh jeez sorry I thought I was responding to another thread where I use apostrophes in one of my prints :\
|
|
|
| Report Abuse |
|
|
|
| 26 Jun 2016 03:35 PM |
UHHHHHHHHHHHH..........So Im Correct then.Yeah but I did forget to put the quotes for print.Instead of print(You Pressed q)
Put print("You Pressed q")
Sorry Guys.Mistakes are made though... |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 26 Jun 2016 03:36 PM |
It's just that KeyDown is deprecated, and you shouldn't use it at all. It may be functional now, but, it might not be in the near future.
|
|
|
| Report Abuse |
|
|
|
| 26 Jun 2016 03:41 PM |
| I used it in ROBLOX Studio and Its working |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 26 Jun 2016 03:42 PM |
yeah, for now but like I said twice already, you shouldn't use it at all. It is subject to removal, as it is deprecated[3]
|
|
|
| Report Abuse |
|
|
|
| 26 Jun 2016 03:44 PM |
| Well if it's deprecated I will try to find another way how to do it |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 26 Jun 2016 03:44 PM |
Use the link to UserInputService that I linked you to above.=
|
|
|
| Report Abuse |
|
|
| |
|
|
| 26 Jun 2016 04:04 PM |
Now I'm going to be showing you people how to make Multiple Background Music
1.You insert a Sound into Workspace
2.Enter A SoundId For Example....I'll be using the SoundId "274015254" Which Is The Song Jetta - I'd Love To Change the world
3.Name The Sound "Sound1"
If You made multiple sounds then name the 2nd Sound "Sound2" and the 3rd sound "Sound3" and you can continue
4.Insert a Local Script
5.In That Local Script type
while true do wait() <- This prevents your game from crashing game.Workspace.Sound1:Play() wait(120) <- I gave the song 2 minutes to play game.Workspace.Sound1:Stop() wait(2) game.Workspace.Sound2:Play() wait(120) game.Workspace.Sound2:Stop() end
With this script,This will allow you to play Multiple Background Music and will loop forever.
If you don't want it to loop forever in the server then remove while true do,the end and the wait that prevents the game from crashing. |
|
|
| Report Abuse |
|
|
|
| 26 Jun 2016 04:06 PM |
One more thing to add.
You must put the LocalScript into StarterGUI
That's All |
|
|
| Report Abuse |
|
|