So I have a script that when you click, a fireball should fire in the direction the player is looking after being welded to the player for 2 seconds, and it works, but if the player is turning when the fireball is shot, the fireball sometimes curves. I am creating a Linear Velocity in script when I fire this. The fireball object only has an attachment for the Linear velocity.
Video of normal vs. curving
Code of firing the ball in the server script.
--References
local RS = game:GetService("ReplicatedStorage")
local Debris = game:GetService("Debris")
local TS = game:GetService("TweenService")
--Gets fireball folder
local Folder = RS:WaitForChild("Attacks"):WaitForChild("Spells"):WaitForChild("Fireball")
--Gets fireball remote and mesh object
local Remote = Folder.FireballRemote
local Fireball = Folder.FireballObj
Remote.OnServerEvent:Connect(function(plr)
local char = plr.Character
local humrp = char:FindFirstChild("HumanoidRootPart")
--Creates a VFX folder
local folder = Instance.new("Folder", plr.Character)
folder.Name = "FireballFX"
--Puts the fireball on the player
local vfx = Fireball:Clone()
vfx.Parent = folder
vfx.CFrame = humrp.CFrame
vfx.Position = humrp.Position
--Welds the fireball onto the player
local weld = Instance.new("ManualWeld")
weld.Name = "VFXWeld"
weld.Part0 = vfx
weld.Part1 = humrp
weld.C0 = weld.Part0.CFrame:ToObjectSpace(weld.Part1.CFrame)
weld.Parent = weld.Part0
--Creates the linear velocity
local velocity = Instance.new("LinearVelocity")
velocity.Enabled = false
velocity.Parent = vfx
velocity.Name = "Velo"
velocity.MaxForce = 1000000
velocity.Attachment0 = velocity.Parent:FindFirstChild("Attachment")
velocity.RelativeTo = 0
delay(1, function()
--Kills the weld and enabled the velocity.
vfx:FindFirstChild(weld.Name):Destroy()
velocity.Enabled = true
velocity.VectorVelocity = Vector3.new(0,0,-60)
Remote:FireClient(plr)
delay(2, function()
if (not vfx:FindFirstChild("FullCVar")) then
folder:Destroy()
end
end)
end)
end)