I'm making a game where if you press 'F' you launch a fireball. This is the script i'm using
game.Players.PlayerAdded:wait()
Player = script.Parent.Parent.Parent -- Gets LocalPlayer
Player.CharacterAdded:wait()
Character = Player.Character
Mouse = Player:GetMouse()
function onKeyDown(key)
if key:lower() == "f" then
local ball = Instance.new("Part")
ball.TopSurface = "Smooth"
ball.BottomSurface = "Smooth"
ball.Shape = "Ball"
ball.Transparency = 0.7
ball.BrickColor = BrickColor.new("Bright red")
ball.Parent = game.Workspace
local fire = Instance.new("Fire")
fire.Parent = ball
fire.Size = 12
fire.Heat = 0
fire.Color = BrickColor.new("Really black")
local velocity = Instance.new("BodyVelocity")
velocity.maxForce = Vector3.new(999, 999, 999)
velocity.velocity = Character.Head.CFrame.lookVector * 50
velocity.Parent = ball
ball.Position = Character.Head.Position + 2
ball.CFrame = Character.Head.CFrame * CFrame.new(0, 0, 10)
end
end
Mouse.KeyDown:connect(onKeyDown)
-- this is placed in a tool inside the starter pack
it doesn't show any errors when i run it, but it doesn't work Can anyone explain what the problem is? I'm pretty new to roblox lua scripting, so sorry if this is a stupid question

3 comments
KeyDown is Deprecated.Instead,use UserInputService and InputBegan.
why are you changing the position first and then the CFrame?
:connect() is outdated. Use it with capital, :Connect(). I would also consider using UserInputService rather than the mouse to detect when the player presses a button. Also, game.Workspace is an old method. You can just type workspace. BrickColors are kinda old, but still usable.