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

Why does this shooting script have a bit offset from the goal`?

local part = script.Parent
wait(2)
while wait(1) do
	local Bullet = Instance.new("Part", workspace)
	Bullet.Size = Vector3.new(1,1,1)
	local BV = Instance.new("BodyVelocity", Bullet)
	BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
	BV.Velocity = (workspace.BadAdmins.HumanoidRootPart.Position - script.Parent.Position).Unit*50 
end

My bullet has a bit of offset and is not hitting me, it is shooting right beside my character. What is the problem?

1 answer

✓ Accepted answer

It appears that you aren't setting the bullet's position where it should go. I assume script.Parent is a gun here. Thus you would want your bullet to start out at the position of your gun, but with this script the bullet actually starts out at the origin (0, 0, 0). After that, the bullet's velocity is calculated using a statement that seems to assume that the bullet starts out inside script.Parent; it creates a vector from the gun to BadAdmins' HumanoidRootPart. All in all, you want to assign the position to an appropriate value:

local part = script.Parent
wait(2)
while wait(1) do
    local Bullet = Instance.new("Part", workspace)
    Bullet.Size = Vector3.new(1,1,1)
    Bullet.Position = part.Position -- Line added here
    local BV = Instance.new("BodyVelocity", Bullet)
    BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
    BV.Velocity = (workspace.BadAdmins.HumanoidRootPart.Position - script.Parent.Position).Unit*50 
end

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