Hey, people of the forum! I was wondering how I can make my Projectile actually accurate with the mouse position. I have it so when you press R a fireball gets launched to where your mouse is pointing, but where it gets shot is nowhere accurate to where the mouse is!
Ill provide the code and a video of what happens.
Here is The code:
local fb = game.ReplicatedStorage:WaitForChild('FireBall')
local Debris = game:GetService('Debris')
local TS = game:GetService('TweenService')
local Animations = script:WaitForChild('Animations')
local Meshes = script:WaitForChild('Meshes')
local speed = 75
local damage = 50
fb.OnServerEvent:Connect(function(player,Direction)
local Char = player.Character
local Hum = Char:WaitForChild('Humanoid')
local Root = Char:WaitForChild('HumanoidRootPart')
local Wave = Meshes:WaitForChild('Wave'):Clone()
local FXFolder = Instance.new('Folder',workspace)
FXFolder.Name = player.Name..' FX'
Debris:AddItem(FXFolder,2)
Wave.CFrame = CFrame.new(Root.CFrame * CFrame.new(0,0,-3).p, Direction.p) --Root.CFrame * CFrame.new(0,0,-3)
Wave.Parent = FXFolder
Wave:SetNetworkOwner(nil)
Wave.Touched:Connect(function(Hit)
if Hit:IsA('BasePart') then
if not Hit: IsDescendantOf(Char) then
local Humanoid = Hit.Parent:FindFirstChild('Humanoid')
if Humanoid then
if Humanoid.Health > 0 then
FXFolder:Destroy()
Humanoid:TakeDamage(damage)
end
else
FXFolder:Destroy()
end
end
end
end)
local Ring = Meshes:WaitForChild('Ring'):Clone()
Ring.CFrame = Wave.CFrame
Ring.Parent = FXFolder
Ring:SetNetworkOwner(nil)
local weld = Instance.new('ManualWeld')
weld.Part0 = Ring
weld.Part1 = Wave
weld.C0 = weld.Part0.CFrame:toObjectSpace(weld.Part1.CFrame)
weld.Parent = weld.Part0
local velocity = Instance.new('BodyVelocity',Wave)
velocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
velocity.Velocity = Direction.LookVector * speed --Root.CFrame.LookVector * speed
fb:FireClient(player)
end)