So I am trying to make a script that when you press a key it will make a fireball that moves, but the problem is that when I press the key the ball just appear and don't move.I used bodyvelocity to move it!
local Player = game.Players.LocalPlayer local Character = Player.Character local Mouse = Player:GetMouse() local debounce = false Mouse.KeyDown:connect(function(key) key = key:lower() if key == "q" and debounce == false then fireball = Instance.new('Part') fireball.Parent = Player.Character fireball.BrickColor = BrickColor.new("Deep orange") fireball.Shape = "Ball" fireball.Material = "Neon" fireball.CFrame = Character.Torso.CFrame * CFrame.new(0,0,-5) bv = Instance.new("BodyVelocity") bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge) bv.Velocity = Character.Torso.CFrame.lookVector*20 bv.Parent = fireball end end)
Hey man, this one was a bit of a challenge to figure out and I'm not totally satisfied with the result but it works! After debugging the issue seemed to be making the PartType a ball. The solution to this is to make it a normal part and put a ball mesh into it. See the completed code below.
local Player = game.Players.LocalPlayer local Character = Player.Character local Mouse = Player:GetMouse() local debounce = false Mouse.KeyDown:connect(function(key) key = key:lower() if key == "q" and debounce == false then -- Create fire ball mesh local specialmesh = Instance.new('SpecialMesh') specialmesh.MeshType = Enum.MeshType.Sphere -- Create fire ball local fireball = Instance.new('Part') fireball.Parent = Player.Character fireball.BrickColor = BrickColor.new("Deep orange") fireball.Shape = Enum.PartType.Block fireball.Material = Enum.Material.Neon fireball.Size = Vector3.new(3, 3, 3) -- Parent the sphere mesh into the part specialmesh.Parent = fireball -- Create a bodyvelocity local bv = Instance.new("BodyVelocity") bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge) bv.Velocity = Character.Torso.CFrame.lookVector*20 bv.Parent = fireball -- Position fire ball fireball.CFrame = Character.Torso.CFrame * CFrame.new(0,0,-5) end end)
P.S Look into using Enum items rather than strings for cleaner code :)