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: UserInput Service

Previous Thread :: Next Thread 
18lpickett is not online. 18lpickett
Joined: 15 Jul 2012
Total Posts: 3121
13 Jul 2015 04:18 PM
I made a previous forum regarding this. I've learned that KeyDown is outdated, and UserInputService is better. I made a script using UserInputService. What im trying to do is when they key is pressed, damage happens in an area around the Player. Heres what i have so far :

local Service = game:GetService("UserInputService")

Service.InputBegan:connect(function(input, recieved)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.R then
print('Input W')
end
end
end)
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
13 Jul 2015 04:21 PM
local uis = game:GetService("UserInputService")

uis.InputBegan:connect(function(input, event)
if not event then
if input.KeyCode == Enum.KeyCode.E then
print("Pressing E")
end
end
end)


"Talk is cheap. Show me the code." - Linus Torvalds
Report Abuse
18lpickett is not online. 18lpickett
Joined: 15 Jul 2012
Total Posts: 3121
13 Jul 2015 04:28 PM
You just changed the keys to E
Report Abuse
18lpickett is not online. 18lpickett
Joined: 15 Jul 2012
Total Posts: 3121
13 Jul 2015 04:33 PM
B1
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
13 Jul 2015 04:33 PM
Its a template with clean code. Now use it. It works in a local script.


"Talk is cheap. Show me the code." - Linus Torvalds
Report Abuse
fishguy100 is not online. fishguy100
Joined: 16 Feb 2013
Total Posts: 3679
13 Jul 2015 04:36 PM
local uis = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Damage = 30 -- The damage done
local Distance = 40 -- How many studs away a player will be to get damaged

uis.InputBegan:connect(function(input, event)
if not event then
if input.KeyCode == Enum.KeyCode.E then
for _,C in next, workspace:GetChildren() do
if C:FindFirstChild("Humanoid") ~= nil and (C.Torso.Position - Player.Character.Torso.Position ).Magnitude < Distance then
C.Humanoid:TakeDamage(Damage)
end
end
end
end
end)
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
13 Jul 2015 04:37 PM
@fishguy100

That doesn't help him at all. Thats just spoon feeding him.

"Talk is cheap. Show me the code." - Linus Torvalds
Report Abuse
18lpickett is not online. 18lpickett
Joined: 15 Jul 2012
Total Posts: 3121
13 Jul 2015 04:38 PM
@Time
The previous script worked fine.
Report Abuse
fishguy100 is not online. fishguy100
Joined: 16 Feb 2013
Total Posts: 3679
13 Jul 2015 06:55 PM
Glad I can help you.


"It takes time to build a game. It takes skill to make it work" ~ fishguy100
Report Abuse
18lpickett is not online. 18lpickett
Joined: 15 Jul 2012
Total Posts: 3121
13 Jul 2015 07:27 PM
@Fish
Sorry i forgot to thank you. This was a big part of my game and you did a lot for me :D
Report Abuse
fishguy100 is not online. fishguy100
Joined: 16 Feb 2013
Total Posts: 3679
13 Jul 2015 07:39 PM
No problem!


"It takes time to build a game. It takes skill to make it work" ~ fishguy100
Report Abuse
18lpickett is not online. 18lpickett
Joined: 15 Jul 2012
Total Posts: 3121
13 Jul 2015 07:39 PM
@Fishguy
It's still hurting the Player. Is there any way to prevent this?
Report Abuse
fishguy100 is not online. fishguy100
Joined: 16 Feb 2013
Total Posts: 3679
13 Jul 2015 07:39 PM
You want it to not hurt the player?


"It takes time to build a game. It takes skill to make it work" ~ fishguy100
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
13 Jul 2015 07:40 PM
fishguy sucks at scripting, he sucks ok. dont trust him
Report Abuse
18lpickett is not online. 18lpickett
Joined: 15 Jul 2012
Total Posts: 3121
13 Jul 2015 07:40 PM
Not the Player That presses it, but those around him/her. It's a 1 Player Game, so they'll be hurting NPC's.
Report Abuse
fishguy100 is not online. fishguy100
Joined: 16 Feb 2013
Total Posts: 3679
13 Jul 2015 07:42 PM
It should still work with NPCs. Also, dont listen to abstractmadness. He is jelous that he cannot script like me. He says he is better but I leave that to the community because I assure you he isnt.


"It takes time to build a game. It takes skill to make it work" ~ fishguy100
Report Abuse
fishguy100 is not online. fishguy100
Joined: 16 Feb 2013
Total Posts: 3679
13 Jul 2015 07:42 PM



"It takes time to build a game.local uis = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Damage = 30 -- The damage done
local Distance = 40 -- How many studs away a player will be to get damaged

uis.InputBegan:connect(function(input, event)
if not event then
if input.KeyCode == Enum.KeyCode.E then
for _,C in next, workspace:GetChildren() do
if C:FindFirstChild("Humanoid") ~= nil and (C.Torso.Position - Player.Character.Torso.Position ).Magnitude < Distance and C.Name ~= Player.Name then
C.Humanoid:TakeDamage(Damage)
end
end
end
end
end)

Heres a fix!


"It takes time to build a game. It takes skill to make it work" ~ fishguy100
Report Abuse
18lpickett is not online. 18lpickett
Joined: 15 Jul 2012
Total Posts: 3121
13 Jul 2015 07:45 PM
Wow, thanks a lot!

If you don't mind, is there a way to play an animation when this key is pressed as well?

Report Abuse
fishguy100 is not online. fishguy100
Joined: 16 Feb 2013
Total Posts: 3679
13 Jul 2015 07:45 PM
Yes. Do you have the animation? Invite me to a party.


"It takes time to build a game. It takes skill to make it work" ~ fishguy100
Report Abuse
fishguy100 is not online. fishguy100
Joined: 16 Feb 2013
Total Posts: 3679
13 Jul 2015 08:04 PM
local Player = game.Players.LocalPlayer
local Damage = 30 -- The damage done
local Distance = 40 -- How many studs away a player will be to get damaged

uis.InputBegan:connect(function(input, event)
if not event then
if input.KeyCode == Enum.KeyCode.E then
local Animation = Instance.new("Animation",Player)
Animation.AnimationId = "http://www.roblox.com/asset/?id=161277815"
Player.Character.Humanoid:LoadAnimation(Animation):Play()

for _,C in next, workspace:GetChildren() do
if C:FindFirstChild("Humanoid") ~= nil and (C.Torso.Position - Player.Character.Torso.Position ).Magnitude < Distance and C.Name ~= Player.Name then
C.Humanoid:TakeDamage(Damage)
end
end
end
end
end)

This should work with animations.

"It takes time to build a game. It takes skill to make it work" ~ fishguy100
Report Abuse
18lpickett is not online. 18lpickett
Joined: 15 Jul 2012
Total Posts: 3121
13 Jul 2015 08:18 PM
I Keep on getting this error with the Animation

20:18:04.209 - httpGet http://www.roblox.com/asset/?id=268576868&serverplaceid=259343955&clientinsert=0 failed. Trying again. Error: HTTP 403 (HTTP/1.1 403 Asset is not trusted for this place). Elapsed time: 0.532401
20:18:04.419 - Content failed for http://www.roblox.com/Asset/?id=268576868&serverplaceid=259343955&clientinsert=0 because HTTP 403 (HTTP/1.1 403 Asset is not trusted for this place)
20:18:04.420 - Content failed because HTTP 403 (HTTP/1.1 403 Asset is not trusted for this place)
Report Abuse
18lpickett is not online. 18lpickett
Joined: 15 Jul 2012
Total Posts: 3121
13 Jul 2015 08:33 PM
B?
Report Abuse
vacha is not online. vacha
Joined: 06 Jan 2011
Total Posts: 1993
13 Jul 2015 08:42 PM
Do you own those animations?

while true do the do
Report Abuse
18lpickett is not online. 18lpickett
Joined: 15 Jul 2012
Total Posts: 3121
13 Jul 2015 08:44 PM
No, it won't work if i don't?
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
13 Jul 2015 08:45 PM
Then thats probably why. You need to own the animations.


"Talk is cheap. Show me the code." - Linus Torvalds
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