Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make a part shoot to the players position using bodyvelocity?


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?

2 comments

0

I believe you should change line 19 to BV.Velocity = human.Character.HumanoidRootPart.CFrame.lookVector * 50

0

no, that will only shoot in the direction the player is looking.

1 answer

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.

2 comments

0

I meant, the bullets are coming from a part. Theres no mouse involved.

0

You can probably strip the Mouse.hit.p and see if anything happens

This discussion is preserved as it was. New answers, comments, and votes are closed.