|
| 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
|
  |
| 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 |
|
|
|
| 13 Jul 2015 04:28 PM |
| You just changed the keys to E |
|
|
| Report Abuse |
|
|
| |
|
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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 13 Jul 2015 04:38 PM |
@Time The previous script worked fine. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 13 Jul 2015 07:39 PM |
@Fishguy It's still hurting the Player. Is there any way to prevent this? |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 13 Jul 2015 07:40 PM |
| fishguy sucks at scripting, he sucks ok. dont trust him |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
| |
|
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 |
|
|
|
| 13 Jul 2015 08:44 PM |
| No, it won't work if i don't? |
|
|
| Report Abuse |
|
|
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 |
|
|