Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can anyone help me change this script so i hit F and it fires and not click my mouse?

this script here

local Selected = false 
local Shoot = true 
function Click(Target) 
if(Target.Target.Parent:findFirstChild("Humanoid")~=nil)then 
Target.Target.Parent.Humanoid.Health = 0 
end 
local P = Instance.new("Part") 
P.Name = "Laser" 
local Place0 = script.Parent.Parent.Parent.Character["Left Arm"].CFrame 
P.formFactor = 0 
P.Size = Vector3.new(7,7,(Place0.p - Target.Hit.p).magnitude) 
P.CFrame = CFrame.new((Place0.p + Target.Hit.p)/2,Place0.p) 
P.Parent = game.Workspace 
P.Material = "Neon"
P.Color = Color3.new(106) 
P.Transparency = 0 
P.Reflectance = 0.5 
P.Anchored = true 
P.CanCollide = false 
local E = Instance.new("Explosion") 
E.Position = Target.Hit.p 
E.Parent = game.Workspace 
for i = 1,10 do 
P.Transparency = 0.5+(i*0.05) 
P.Reflectance = i*0.05 
wait(0.1) 
end 
P:Remove() 
end 
function Select(Mouse) 
local Arm = script.Parent.Parent.Parent.Character:findFirstChild("Left Arm") 
if(Arm==nil)then 
script.Parent:Remove() 
script:Remove() 
end 
Selected = true 
local Torso = script.Parent.Parent.Parent.Character:findFirstChild("Torso") 
if(Torso==nil)then 
script.Parent:Remove() 
script:Remove() 
end 
local ArmWeld = Torso:findFirstChild("Left Shoulder") 
if(ArmWeld~=nil)then 
ArmWeld.Parent = nil 
end 
--Mouse.Button1Down:connect(function()Click(Mouse)end) 
function onKeyDown(key)

if key == "t" then
Arm.Anchored = true 
while Selected do 
local Place0 = script.Parent.Parent.Parent.Character.Torso.CFrame 
Place0 = Place0 + ((Place0 * CFrame.fromEulerAnglesXYZ(math.pi/2,0,0)).lookVector * 0.5) + (Place0 *        CFrame.fromEulerAnglesXYZ(0,math.pi/2,0)).lookVector 
local Place1 = Place0 + ((Place0.p-Mouse.Hit.p).unit * -2) 
Arm.CFrame = CFrame.new((Place0.p + Place1.p)/2,Place0.p) * CFrame.fromEulerAnglesXYZ(-math.pi/2,0,0) 
wait() 
end 

end
Arm.Anchored = false 
if(ArmWeld~=nil)then 
ArmWeld.Parent = Torso 
end 
end 
function Deselect() 
Selected = false 
end 
script.Parent.Selected:connect(Select) 

I tried to were inset of a mouse click...you hit F and it would fire, I have no clue what to do.. help?

7 comments

0

Can you please use a code block? It would make your question so much easier to answer.

0

Also, there are many outdated events in this script, so I am assuming the code isn't yours. Use Connect instead of connect. Also, use :Destroy() instead of Remove(). However, if you wish to access the instance again later, just set its parent to nil rather than destroy it.

0

I agree with lunatic, your code is almost unreadable without codeblocks.

0

Please refrain from posting code that is not yours.

0

ok i found out how to add a code block.. so, how can i have it were i hit F and not mouse click?

0

and your right... this script isnt mine..i bought it form someone for robux a few months ago it was good but now..i need it to fire when i hit F, and it seems the one i bought it from has dissaperd off of the internet

0

Oh, sorry to here that they dissaperd.

1 answer

I'm not really going to go into too much detail because this isn't even your code, but I'll post a link to a useful wiki page if you really want to learn how to do this. Here is the code you would use to fire something when the F key is pressed:

game:GetService("UserInputService").InputBegan:Connect(function(input, gpe) --when any input from the player is detected
	if gpe then return end --if the player is chatting then do not run the code
	if input.KeyCode == Enum.KeyCode.F then --if the input detected is the "f" key being pressed
		--code
	end
end)

Here are some useful links:

https://wiki.roblox.com/index.php?title=API:Class/UserInputService https://wiki.roblox.com/index.php?title=API:Class/UserInputService/InputBegan

6 comments

0

Also, I see in the code you posted that you are using findFirstChild() as well. Please refrain from using deprecated and outdated code. Use FindFirstChild() instead. Here's a RobloxDev article on why deprecated code is bad to use and how it affects your game: http://robloxdev.com/articles/Deprecation

0

thing is it is my code, i bought it via robux. the maker of it dissaperd on me.. and i have no clue were i would put something like that or how to get it working

0

What incapaz and I are trying to say is that you didn't write the code yourself. It is hard to help someone with code that they didn't write, because if that's the case they usually have little to no idea or experience in that field.

0

Also, I'm a bit skeptical that you bought this code from someone and that the person you bought it from "dissaperd" right after. I'm kind of leaning toward you using a free model. However, if that isn't the case, please try to get in contact with the person you bought the code from and tell them to indent their code properly.

0

you callin me a lier?

This discussion is preserved as it was. New answers, comments, and votes are closed.