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 this humanoid shoot in the target direction?

torso = script.Parent.Torso
maxrange = 70
minrange = 20
target = nil
tor = nil

function findNearestTarget()
	plrs = game.Players:GetChildren()
	for i, plr in ipairs(plrs) do
		if plr.Character ~= nil then
			if plr.Character:findFirstChild("Humanoid") and plr.Character.Humanoid.Health>0 then
				tor = plr.Character.Torso
				if target == nil then
					if ((torso.Position - tor.Position).magnitude <= maxrange)  then
						if ((torso.Position - tor.Position).magnitude >= minrange) then
							target = plr.Character
						else
							target = nil
							script.Parent.Zombie:MoveTo(script.Parent.Head.Position, script.Parent.Head)
						end		
					else
						target = nil
						script.Parent.Zombie:MoveTo(script.Parent.Head.Position, script.Parent.Head)
					end
				end
			end
		end
	end
end

head = script.Parent:WaitForChild("Head")

function Shoot ()
	local ball = Instance.new("Part")
	ball.Name = "Ball"
	ball.BrickColor = BrickColor.new("White")
	ball.Shape = "Ball"
	ball.Size = Vector3.new(1,1,1)
	ball.CanCollide = false
	ball.CFrame = head.CFrame
	ball.Velocity = tor.CFrame*20
	ball.Parent = game.Workspace
end

while true do
	wait(.1)
	findNearestTarget()
	if target ~= nil then
		wait(2)
		Shoot()
		print ("Shooted")
	end
end

So, what this is supposed to do, is that when this humanoid has a target he shoots on its direction. But he shoots downward and not on the targets direction. Help?

1 answer

the FrontSurface of the part that the ball ball comes out off has to Face ere he is Facing...

2 comments

0

hes shooting downwards

0

dude -_- u dont kno nothing! :P I made my Gun like a fe Days ago, I made the same Mistake :P I learned from my Mistake... the Front Surface needs to be facing forards, cos if there's no focus part, then the only choice for the system is the front surface :P try it, believe me... u dont just Thumbs Don cos u think it's rong :P try it first then Judge...

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