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: Key "E" pressed

Previous Thread :: Next Thread 
DeathsLASTwords is not online. DeathsLASTwords
Joined: 28 Jan 2012
Total Posts: 2701
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 is not online. 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
DeathsLASTwords is not online. DeathsLASTwords
Joined: 28 Jan 2012
Total Posts: 2701
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
DeathsLASTwords is not online. DeathsLASTwords
Joined: 28 Jan 2012
Total Posts: 2701
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
DeathsLASTwords is not online. DeathsLASTwords
Joined: 28 Jan 2012
Total Posts: 2701
05 Aug 2015 11:02 AM
Bump.. Surely someone knows this.
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
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
DeathsLASTwords is not online. DeathsLASTwords
Joined: 28 Jan 2012
Total Posts: 2701
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
LunaScripter is not online. LunaScripter
Joined: 27 Nov 2008
Total Posts: 813
05 Aug 2015 11:12 AM
(bomb.CFrame.p - Torso.CFrame.p).magnitude < 5


- This is the will of Steins;Gate
Report Abuse
buildersteven4 is not online. buildersteven4
Joined: 08 May 2009
Total Posts: 1325
05 Aug 2015 11:16 AM
@Luna Why would you use the CFrame property when you only need the position???
Report Abuse
DeathsLASTwords is not online. DeathsLASTwords
Joined: 28 Jan 2012
Total Posts: 2701
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
DeathsLASTwords is not online. DeathsLASTwords
Joined: 28 Jan 2012
Total Posts: 2701
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
DeathsLASTwords is not online. DeathsLASTwords
Joined: 28 Jan 2012
Total Posts: 2701
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
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
05 Aug 2015 11:39 AM
What are you trying to do?
Report Abuse
instawin is not online. 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
DeathsLASTwords is not online. DeathsLASTwords
Joined: 28 Jan 2012
Total Posts: 2701
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 is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
05 Aug 2015 11:56 AM
that's what you wanted.. is it not?
Report Abuse
DeathsLASTwords is not online. DeathsLASTwords
Joined: 28 Jan 2012
Total Posts: 2701
05 Aug 2015 11:57 AM
and then, if that player presses E, it will perform some code.
Report Abuse
instawin is not online. 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
DeathsLASTwords is not online. DeathsLASTwords
Joined: 28 Jan 2012
Total Posts: 2701
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 is not online. 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
DeathsLASTwords is not online. DeathsLASTwords
Joined: 28 Jan 2012
Total Posts: 2701
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 is not online. 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 is not online. Expatiate
Joined: 29 Jun 2013
Total Posts: 2358
05 Aug 2015 12:36 PM
cs;go game pls
Report Abuse
instawin is not online. 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
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