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: KeyDown?

Previous Thread :: Next Thread 
error9999 is not online. error9999
Joined: 05 Sep 2009
Total Posts: 1593
12 Jul 2016 05:09 PM
Greetings,

Last time I played roblox, you had to use mouse.KeyDown(key) to make a script do something when you press a key, but apparently this has changed??

How would I do this now?
Report Abuse
Ptwisted is not online. Ptwisted
Joined: 13 Feb 2013
Total Posts: 568
12 Jul 2016 05:11 PM
UserInputService


Report Abuse
error9999 is not online. error9999
Joined: 05 Sep 2009
Total Posts: 1593
12 Jul 2016 05:15 PM
Could you be so kind and give me the function I'd need to use to do the same as keydown(key) and an other function which does the same as mouse.Move(x,y)?

I checked that userinputservice but I can't figure that out :s
Report Abuse
Ptwisted is not online. Ptwisted
Joined: 13 Feb 2013
Total Posts: 568
12 Jul 2016 05:21 PM
local UIS = game:GetService("UserInputService")

UIS.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.B then
print(game.Players.LocalPlayer.Name.." pressed B.")
end
end)


Report Abuse
error9999 is not online. error9999
Joined: 05 Sep 2009
Total Posts: 1593
12 Jul 2016 05:25 PM
ok so that is fixed now.


But how can I get the position where my mouse is with userinputservice?

Report Abuse
Ptwisted is not online. Ptwisted
Joined: 13 Feb 2013
Total Posts: 568
12 Jul 2016 05:30 PM
Not UserInputService but this is what I usually do.

local mousePos = coroutine.create(function()
local mouse = game.Players.LocalPlayer:GetMouse()
while wait() do
print(mouse.Hit.p)
end
end)
coroutine.resume(mousePos)


Report Abuse
error9999 is not online. error9999
Joined: 05 Sep 2009
Total Posts: 1593
12 Jul 2016 05:33 PM
wouldn't this cause lag if there are plenty people ingame?

I need to find a way to not lag the server (so doing it locally would be fine), and so it doesn't seem to glitch, so rather smooth.
Report Abuse
RangerDelta is not online. RangerDelta
Joined: 10 Jul 2016
Total Posts: 1194
12 Jul 2016 05:36 PM
Why do you need UserInputService to get the position of the mouse? Just use the mouse's properties. And this is all client-side so no, no lag.


Report Abuse
Ptwisted is not online. Ptwisted
Joined: 13 Feb 2013
Total Posts: 568
12 Jul 2016 05:38 PM
"wouldn't this cause lag if there are plenty people ingame?

I need to find a way to not lag the server (so doing it locally would be fine), and so it doesn't seem to glitch, so rather smooth."

This would be in a local script obv because you're getting the player's mouse.


Report Abuse
error9999 is not online. error9999
Joined: 05 Sep 2009
Total Posts: 1593
12 Jul 2016 05:48 PM
Yhea excuse me for that.


So using "mouse.Move" will now get me like the position of where the mouse is, on my screen.
But how would I now get the point the mouse is currently at in (x,y,z)?
Report Abuse
Ptwisted is not online. Ptwisted
Joined: 13 Feb 2013
Total Posts: 568
12 Jul 2016 05:50 PM
mouse.Hit.p


Report Abuse
error9999 is not online. error9999
Joined: 05 Sep 2009
Total Posts: 1593
12 Jul 2016 05:53 PM
I should've know that.

Thank you for your time!
Report Abuse
alelollo is not online. alelollo
Joined: 27 Jun 2013
Total Posts: 33
12 Jul 2016 05:58 PM
It hasnt changed u can still use keydown


game:GetService'Players'.LocalPlayer:GetMouse().KeyDown:connect(function(key)
if key=="e" then
game.Players.LocalPlayer.Character:BreakJoints()
end
end)
Report Abuse
error9999 is not online. error9999
Joined: 05 Sep 2009
Total Posts: 1593
12 Jul 2016 06:01 PM
Yhea I noticed that, but since the wiki says you better not use it I'll just use the new method.
Report Abuse
DurstAuric is not online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
12 Jul 2016 06:09 PM
@alelollo
KeyDown is deprecated and people should not encourage others to use it. It can break at any given moment and it won't ever be fixed, or most likely won't.

@OP
-- LocalScript
function GetMousePosition()
local Mouse = game:GetService("Players").LocalPlayer:GetMouse()
return Mouse.Origin
end
game:GetService("UserInputService").InputBegan:connect(function(Input, GameEvent)
if Input == Enum.UserInputType.MouseButton1 and not GameEvent then
print(GetMousePosition())
end
end)


( ͡• ◡ ͡•) -=[ RAP: 359,266 || DurstAuric; the narb of ROBLOX ]=- ( ͡• ◡ ͡•)
Report Abuse
DurstAuric is not online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
12 Jul 2016 06:12 PM
Actually, don't use mine. It doesn't work. Hold on.


( ͡• ◡ ͡•) -=[ RAP: 359,249 || DurstAuric; the narb of ROBLOX ]=- ( ͡• ◡ ͡•)
Report Abuse
Ptwisted is not online. Ptwisted
Joined: 13 Feb 2013
Total Posts: 568
12 Jul 2016 06:13 PM
@DurstAuric

Thanks for sharing your method, I think I like that better. Is there a difference between mouse.Origin and mouse.Hit.p in terms of position?


Report Abuse
Ptwisted is not online. Ptwisted
Joined: 13 Feb 2013
Total Posts: 568
12 Jul 2016 06:13 PM
"Actually, don't use mine. It doesn't work. Hold on."

oh lol I wait for you to fix it


Report Abuse
error9999 is not online. error9999
Joined: 05 Sep 2009
Total Posts: 1593
12 Jul 2016 06:22 PM
Currently I just use this:

mouse.Move:connect(function()
if mouse.Hit then
print(mouse.Hit.P)
end end)

so this will just print where the mouse is, if the mouse is moving over a part.
Report Abuse
DurstAuric is not online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
12 Jul 2016 06:23 PM
Mouse.Origin returns the mouse's position in the world, much like Mouse.Hit. The difference is that it doesn't need to use any input of some sort to return its position.


( ͡• ◡ ͡•) -=[ RAP: 359,241 || DurstAuric; the narb of ROBLOX ]=- ( ͡• ◡ ͡•)
Report Abuse
error9999 is not online. error9999
Joined: 05 Sep 2009
Total Posts: 1593
12 Jul 2016 06:25 PM
so hovering over a void will just print really big number then?
Report Abuse
DurstAuric is not online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
12 Jul 2016 06:29 PM
I would think so.


( ͡• ◡ ͡•) -=[ RAP: 359,280 || DurstAuric; the narb of ROBLOX ]=- ( ͡• ◡ ͡•)
Report Abuse
error9999 is not online. error9999
Joined: 05 Sep 2009
Total Posts: 1593
12 Jul 2016 06:31 PM
Well I better use that then.


Thank you people for your help.
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