|
| 05 Aug 2015 10:37 AM |
| Hello everyone, Im trying to make a bomb that has been planted be able to be defused. I already have the bomb, and the countdown and plant,explosion, etc. done. I just dont know how you would be able to make it when youre right next to the bomb, and press E, it would start to defuse. Since Keyboard input is now deprecated, how would i go doing this? |
|
|
| Report Abuse |
|
|
Fedorakid
|
  |
| Joined: 17 Jul 2010 |
| Total Posts: 7079 |
|
|
| 05 Aug 2015 10:42 AM |
game:GetService("UserInputService").InputBegan:connect(function(inputObject, GPE) if inputObject.KeyCode == Enum.KeyCode.Z and not GPE then --dost00f end end) |
|
|
| Report Abuse |
|
|
|
| 05 Aug 2015 10:45 AM |
| Now if I wanted the player to be close to the object( lets say, 5 bricks) what would I do for this? region3? :/ |
|
|
| Report Abuse |
|
|
|
| 05 Aug 2015 10:51 AM |
How would I make it the local player anyways? I figured out how I would do the nearby defuse, but I need only the local player's input, however, this doesnt seem to work, should It be a localscript?
script.Parent.Touched:connect(function(hit) game:GetService("UserInputService").InputBegan:connect(function(inputObject, GPE) if inputObject.KeyCode == Enum.KeyCode.E and not GPE then print("Hello, local player has pressed E") end end) end)
|
|
|
| Report Abuse |
|
|
|
| 05 Aug 2015 11:02 AM |
| Bump.. Surely someone knows this. |
|
|
| Report Abuse |
|
|
|
| 05 Aug 2015 11:09 AM |
| Detect when they press E, then compare Magnitude of their Torso and said bomb. If close enough, run the code. |
|
|
| Report Abuse |
|
|
|
| 05 Aug 2015 11:10 AM |
| how do i detect that the player nearby is doing it? I cant seem to figure that part out, I understand everything else. |
|
|
| Report Abuse |
|
|
|
| 05 Aug 2015 11:12 AM |
(bomb.CFrame.p - Torso.CFrame.p).magnitude < 5
- This is the will of Steins;Gate |
|
|
| Report Abuse |
|
|
|
| 05 Aug 2015 11:16 AM |
| @Luna Why would you use the CFrame property when you only need the position??? |
|
|
| Report Abuse |
|
|
|
| 05 Aug 2015 11:19 AM |
| when i said the player, I need to only detect THAT player is doing it, as in a local player. |
|
|
| Report Abuse |
|
|
|
| 05 Aug 2015 11:24 AM |
Current script:
script.Parent.Touched:connect(function(hit) if (script.Parent.CFrame.p - hit.Parent.Torso.CFrame.p).magnitude < 5 then game:GetService("UserInputService").InputBegan:connect(function(inputObject, GPE) if inputObject.KeyCode == Enum.KeyCode.E and not GPE then print("Hello, local player has pressed E") end end end) end) |
|
|
| Report Abuse |
|
|
|
| 05 Aug 2015 11:28 AM |
There seems to be an error with the script too:
11:28:25.129 - Workspace.Explosive.Head.Script:8: ')' expected (to close '(' at line 3) near 'end' |
|
|
| Report Abuse |
|
|
|
| 05 Aug 2015 11:39 AM |
| What are you trying to do? |
|
|
| Report Abuse |
|
|
instawin
|
  |
| Joined: 04 Jun 2013 |
| Total Posts: 8777 |
|
|
| 05 Aug 2015 11:55 AM |
game:GetService("UserInputService").InputBegan:connect(function(input, gpe) if gpe then return end if input.KeyCode == Enum.KeyCode.E then if (game.Players.LocalPlayer.Torso.Position - yourBomb.Position).magnitude > 5 then return end
-- stuff end end) |
|
|
| Report Abuse |
|
|
|
| 05 Aug 2015 11:55 AM |
| When a player gets close, it will only detect that player's input, if his magnitude is 5 away. |
|
|
| Report Abuse |
|
|
instawin
|
  |
| Joined: 04 Jun 2013 |
| Total Posts: 8777 |
|
|
| 05 Aug 2015 11:56 AM |
| that's what you wanted.. is it not? |
|
|
| Report Abuse |
|
|
|
| 05 Aug 2015 11:57 AM |
| and then, if that player presses E, it will perform some code. |
|
|
| Report Abuse |
|
|
instawin
|
  |
| Joined: 04 Jun 2013 |
| Total Posts: 8777 |
|
|
| 05 Aug 2015 12:00 PM |
game:GetService("UserInputService").InputBegan:connect(function(input, gpe) if gpe then return end if input.KeyCode == Enum.KeyCode.E then if (game.Players.LocalPlayer.Torso.Position - yourBomb.Position).magnitude > 5 then return end
-- your code end end) [2] |
|
|
| Report Abuse |
|
|
|
| 05 Aug 2015 12:02 PM |
Current script:
local player = game.Players.LocalPlayer local character = player.Character game:GetService("UserInputService").InputBegan:connect(function(input, gpe) if gpe then return end if input.KeyCode == Enum.KeyCode.E then if (character.Torso - script.Parent.Position).magnitude > 5 then return end print("hello game") end end)
Heres the error, i have no idea what this means.. 12:01:19.740 - Workspace.Explosive.Head.Script:6: bad argument #1 to '?' (Vector3 expected, got Object)
|
|
|
| Report Abuse |
|
|
instawin
|
  |
| Joined: 04 Jun 2013 |
| Total Posts: 8777 |
|
|
| 05 Aug 2015 12:06 PM |
*character.Torso.Position
and since that script is inside of the bomb, i have a feeling that this isn't a local script
and if it is, this won't work in online mode
put the local script as a descendant of the player (playergui, playerscripts, backpack, whatever)
|
|
|
| Report Abuse |
|
|
|
| 05 Aug 2015 12:14 PM |
@instawin
Since the item is originally in Lighting(explosive) and is triggered by an event, this is what i put:
local player = game.Players.LocalPlayer local character = player.Character explosive = game.Workspace:WaitForChild("Explosive") game:GetService("UserInputService").InputBegan:connect(function(input, gpe) if gpe then return end if input.KeyCode == Enum.KeyCode.E then if (character.Torso.Position - explosive.Position).magnitude > 5 then return end print("hello game") end end)
and I put this localscript into StarterGui, would all of this be fine? |
|
|
| Report Abuse |
|
|
instawin
|
  |
| Joined: 04 Jun 2013 |
| Total Posts: 8777 |
|
|
| 05 Aug 2015 12:19 PM |
| ye, but the only problem i would see is that it would only wait for the bomb once. what if the bomb is destroyed from workspace after it is defused(or explodes on you if you fail to defuse it lol), and then re-added to workspace again? |
|
|
| Report Abuse |
|
|
Expatiate
|
  |
| Joined: 29 Jun 2013 |
| Total Posts: 2358 |
|
| |
|
instawin
|
  |
| Joined: 04 Jun 2013 |
| Total Posts: 8777 |
|
|
| 05 Aug 2015 12:39 PM |
local player = game.Players.LocalPlayer local character = player.Character explosive = game.Workspace:WaitForChild("Explosive") game:GetService("UserInputService").InputBegan:connect(function(input, gpe) if gpe then return end if input.KeyCode == Enum.KeyCode.E and workspace:FindFirstChild("Explosive") then if (character.Torso.Position - explosive.Position).magnitude > 5 then return end print("hello game") end end)
just do this to counteract the problem that a bomb may not 100% exist all the time |
|
|
| Report Abuse |
|
|