function check() for _, v in pairs(game.Players:GetPlayers()) do if v.Character then if (v.Character.HumanoidRootPart.Position - script.Parent.Position).magnitude < 10 then return v end end end end while wait(0.1) do local human = check() if human ~= nil then local bullet = Instance.new("Part") bullet.CanCollide = false bullet.Position = script.Parent.Position local BV = Instance.new("BodyVelocity") BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge) BV.Velocity = human.Character.HumanoidRootPart.Position bullet.Parent = workspace BV.Parent = bullet end end
My code doesn't work properly. It doesn't shoot to where the humanoidrootpart is, how would i fix this?
Tricky stuff, that's how I did this in one of my CIWS scripts.
blt.BodyVelocity.Velocity = (Mouse.hit.p - workspace.Upper.Fire.Position).unit * 1200
Mouse.hit.p being the target the bullet will be shooting towards, the workspace.Upper.Fire.Position being the start position, .unit * 1200 actually doing all of the magic and adjusting the speed of the thing.