Player = script.Parent.Parent mouse = Player:GetMouse()
function onKeyDown(key) key = key:lower() if key == "f" then x = Instance.new("Part") x.BrickColor = BrickColor.new("Bright red") x.Size = Vector3.new(10, 10, 10) x.TopSurface = "Smooth" x.BottomSurface = "smooth" x.Shape = "Ball" x.Transparency = 0.7 y = Instance.new("BodyVelocity") y.maxForce = Vector3.new(math.huge, math.huge, math.huge) y.Velocity = Player.Character.Torso.CFrame.lookVector *80 x.Parent = Workspace y.Parent = x f = Instance.new("Fire",x) f.Size = 12 f.Heat = 0 game.Debris.AddItem(x, 6) end end
mouse.KeyDown:connect(OnKeyDown)
19:16:24.821 - Attempt to connect failed: Passed value is not a function 19:17:14.066 - attempt to call a nil value
Remember, Lua is CASE-SENSITIVE. The function you created is called onKeyDown
, but your calling OnKeyDown
. You have to call it with the O lower case.
There are a couple of other errors in your code, the first being you make the BottomSurface of the part "smooth", when it needs to be "Smooth". Also AddItem is a method of Debris, so you need a :
not a .
Also, the method of detecting key presses is deprecated, so it recommended you use UserInputService
or ContextActionService
instead. Look those up in the wiki if your interested.