So, I am making a fireball script when a player press F and it works except for the rotation of the fireball, i want the rotation to be facing the same way the player is facing and I don't know what I did wrong here.
local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() CanShoot = true In = false repeat wait() until plr.Character local char = plr.Character mouse.KeyDown:connect(function(key) if key == "f" then if CanShoot == true and In == false then In = true CanShoot = false local part = Instance.new("Part") local fire = Instance.new("Fire",part) local Mesh = Instance.new("SpecialMesh",part) fire.Size = 3.4 Mesh.MeshId = "rbxassetid://475201433" Mesh.Scale = Vector3.new(0.1,0.1,0.1) Mesh.TextureId = "rbxassetid://475201512" part.Parent = workspace part.Name = 'FireBall' part.CanCollide = false part.Anchored = true part.Position = plr.Character.Torso.Position local move = Instance.new("BodyVelocity", part) move.MaxForce = Vector3.new(math.huge,math.huge,math.huge) move.Velocity = plr.Character.Torso.CFrame.lookVector*100 wait(3) part:Destroy() CanShoot = true In = false end end end)
The Problem Is At Line 26 And I Don't Know What I Did Wrong Here.
Remove Line 26 and replace it with this. [MAKE SURE THE PART IS NOT ANCHORED!]
local move = Instance.new("BodyVelocity", part) move.MaxForce = Vector3.new(math.huge,math.huge,math.huge) move.Velocity = plr.Character.Torso.CFrame.lookVector*100
We will create an object called BodyVelocity. Then we will change the MaxForce (or max power) and changing the Velocity to face the character's direction, defined as
plr.Character.Torso.CFrame.lookVector . lookVector is the property of CFrame, AND NO OTHER ELSE!! lookVector just means where an object is looking or where the surface called FrontSurface of a part is facing. You can change the
100 to something else since it tells how fast it is going, and 100 is kinda fast. Hope this helps!