|
| 28 Dec 2015 02:29 PM |
How do I do it so it check if tool is equipped and you click R
function onKeyPress(actionName, userInputState, inputObject) if userInputState == Enum.UserInputState.Begin then print("FIRE") local laser = game.ServerStorage.laser local main = game.Workspace.laserGun.laserIn
wait(1) -- !!! local laserCopy = laser:Clone() -- Local variables are faster and more efficient. laserCopy.Parent = game.Workspace laserCopy.CFrame = main.CFrame laserCopy.BodyVelocity.Velocity = main.CFrame.lookVector*200 laserCopy.BodyVelocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge) delay(2, function() laserCopy:Destroy() end)
end end |
|
|
| Report Abuse |
|
|
| |
|
instawin
|
  |
| Joined: 04 Jun 2013 |
| Total Posts: 8777 |
|
|
| 28 Dec 2015 04:23 PM |
yourTool.Equipped:connect(function() game:GetService("UserInputService").InputBegan:connect(function(input, gpe) if not gpe and input.KeyCode == Enum.KeyCode.R then print(game.Players.LocalPlayer.Name.." pressed r") end end) end)
the function you provided in your post seems to rely on ContextActionService. I haven't really messed with it, so I provided an example which uses UserInputService.
If you wanted to use your function, then take a look at one of the parameters you provided with your function. The inputObject. Just check if the inputObject's KeyCode is equal to the R key enum. Which is pretty much just this:
if inputObject.KeyCode == Enum.KeyCode.R then |
|
|
| Report Abuse |
|
|
| |
|
|
| 28 Dec 2015 04:40 PM |
could i do like
equipped = true
then
if equipped =- true |
|
|
| Report Abuse |
|
|
instawin
|
  |
| Joined: 04 Jun 2013 |
| Total Posts: 8777 |
|
|
| 28 Dec 2015 04:44 PM |
What do you mean? Just use the equipped event.
http://wiki.roblox.com/index.php?title=API:Class/Tool/Equipped
Actually, it probably wouldn't hurt to keep track of whether the tool is equipped or not with a bool.
local equipped = false
yourTool.Equipped:connect(function() game:GetService("UserInputService").InputBegan:connect(function(input, gpe) if not gpe and input.KeyCode == Enum.KeyCode.R and equipped then print(game.Players.LocalPlayer.Name.." pressed r") end end) end)
yourTool.Unequipped:connect(function() equipped = false end) |
|
|
| Report Abuse |
|
|
instawin
|
  |
| Joined: 04 Jun 2013 |
| Total Posts: 8777 |
|
|
| 28 Dec 2015 04:45 PM |
whoops
local equipped = false
yourTool.Equipped:connect(function() equipped = true game:GetService("UserInputService").InputBegan:connect(function(input, gpe) if not gpe and input.KeyCode == Enum.KeyCode.R and equipped then print(game.Players.LocalPlayer.Name.." pressed r") end end) end)
yourTool.Unequipped:connect(function() equipped = false end) |
|
|
| Report Abuse |
|
|
|
| 28 Dec 2015 04:47 PM |
Can someone explain it a bit more
I have this so far
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local char = player.Character
script.Parent.Activated:connect(function() local mH = mouse.Hit local p = Instance.new("Part", game.Workspace) p.Name = "red" p.FormFactor = "Custom" p.Size = Vector3.new(.1, .1, 1) p.BrickColor = BrickColor.Black() p.CanCollide = false p.CFrame = script.Parent.Handle.CFrame * CFrame.new(char.Torso.CFrame.lookVector * 2)-- 2 p.CFrame = CFrame.new (p.Position, mH.p) local bv = Instance.new("BodyVelocity", p) bv.Velocity = p.CFrame.lookVector * 120 bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge) p.Position = p.CFrame.p + Vector3.new(0, 0.1, 0) p.Touched:connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") -- if humanoid then -- humanoid:takeDamage(10) -- end end) end)
|
|
|
| Report Abuse |
|
|
|
| 28 Dec 2015 04:48 PM |
lol wait i read the wrong thing let me go back
|
|
|
| Report Abuse |
|
|
|
| 28 Dec 2015 04:52 PM |
I don't see any outputs hm
local equipped = false
yourTool.Equipped:connect(function() equipped = true game:GetService("UserInputService").InputBegan:connect(function(input, gpe) if not gpe and input.KeyCode == Enum.KeyCode.R and equipped then print(game.Players.LocalPlayer.Name.." pressed r") end end) end)
yourTool.Unequipped:connect(function() equipped = false end)
|
|
|
| Report Abuse |
|
|
|
| 28 Dec 2015 05:11 PM |
| ^ and I did name the variable |
|
|
| Report Abuse |
|
|
instawin
|
  |
| Joined: 04 Jun 2013 |
| Total Posts: 8777 |
|
|
| 28 Dec 2015 05:15 PM |
| What did you define yourTool as? Is it a local script? Where did you place the script? |
|
|
| Report Abuse |
|
|
|
| 28 Dec 2015 06:02 PM |
> tool is in starterpack > regular script > tool is script.Parent |
|
|
| Report Abuse |
|
|
| |
|
instawin
|
  |
| Joined: 04 Jun 2013 |
| Total Posts: 8777 |
|
|
| 28 Dec 2015 11:35 PM |
I know this is really late, but I wasn't foruming for a while.
The script needs to be a _local_ script. |
|
|
| Report Abuse |
|
|
usermvp
|
  |
| Joined: 29 Jun 2013 |
| Total Posts: 188 |
|
|
| 28 Dec 2015 11:36 PM |
Use a local script when scripting guns/tools all the time.
~Previously known as Zztheses |
|
|
| Report Abuse |
|
|
|
| 29 Dec 2015 04:43 AM |
No outputs hm.
yourTool = script.Parent
local equipped = false
yourTool.Equipped:connect(function() equipped = true game:GetService("UserInputService").InputBegan:connect(function(input, gpe) if not gpe and input.KeyCode == Enum.KeyCode.R and equipped then print(game.Players.LocalPlayer.Name.." pressed r") end end) end)
yourTool.Unequipped:connect(function() equipped = false end) |
|
|
| Report Abuse |
|
|