you can have the whole module tbh i don’t avre
local runservice = game:GetService("RunService")
local module = {}
function module.Launch(start, target, force, acceleration, cleanupTime)
local bullet = game.ServerStorage.Bullet:Clone()
bullet.Parent = game.Workspace.Bullets
local t = 0
local prevPos = Vector3.new(0,1e36,0)
local newforce = (target - start).Unit * force
local params = RaycastParams.new()
local exTable = {}
for i,v in ipairs(workspace.Bullets:GetChildren()) do
if v:IsA("BasePart") then
table.insert(exTable,v)
end
end
-- acceleration *= Vector3.new(2,1,2)
-- force *= (Vector3.one*2)
params.FilterDescendantsInstances = exTable
connection = runservice.Stepped:Connect(function(time,delta)
t += delta -- for a stepped or heartbeat event
local newPos = Vector3.new(
start.X + newforce.X * t + (acceleration.X * t^2)/2,
start.Y + newforce.Y * t + (acceleration.Y * t^2)/2,
start.Z + newforce.Z * t + (acceleration.Z * t^2)/2
)
bullet.Position = newPos
local result = workspace:Raycast(newPos,prevPos-newPos,params)
-- RAY VISUALISATION IGNORE THIS
local distance = (newPos - prevPos).Magnitude
local position = (newPos + prevPos)/2
local p = Instance.new("Part",workspace.Bullets)
p.Anchored = true
p.CanCollide = false
p.CanQuery = false
p.Size = Vector3.new(0.1, 0.1, distance)
p.Color = Color3.fromRGB(math.random(0,255),math.random(0,255),math.random(0,255))
p.Transparency = math.random(0,600)/1000
p.Material = Enum.Material.Neon
p.CFrame = CFrame.lookAt(newPos, position)*CFrame.new(0, 0, -distance/2)
-- more code down here
if result and result.Position then
connection:Disconnect()
print(result.Instance)
else
print("failed")
end
prevPos = newPos
if t >= cleanupTime then
-- connection:Disconnect()
bullet:Destroy()
end
end)
end
return module
and this is an example of how i used it
tool.Activated:Connect(function()
-- print(character,player,humanoid,root)
local originPos = root.Position + root.CFrame.LookVector * 1.5
local hitPos = mousehit:InvokeClient(player)
module.Launch(
originPosition, --start
hitPos, --target
100, --force (number, just put ur speed there)
CFrame.new(0,0,0), -- acceleration (gravity)
4 --cleanup time (seconds until bullet destroys itself if it does not find a target)
)
end)