Hello, I’m very new to DevForum, but I need help. I’m having problems in a section of my bullet script where the “hit” follows the lookVector from the bullet. Here’s the whole code of my script:
ball = script.Parent
position = ball.Position
damage = 53
function bulletImpact(bullet,part)
local hole = bullet:Clone()
hole.Size=Vector3.new(0.5,0.5,0.5)
hole.Shape="Ball"
hole.CanCollide=false
hole.Position=bullet.Position
hole.Transparency=1
hole.Name="BulletHole"
hole.Parent=part
print(hole,"-",hole.Parent)
print'hole'
local weld = Instance.new("WeldConstraint")
weld.Part0=hole
weld.Part1=part
weld.Parent=hole
local lookvector1 = bullet.CFrame.lookVector
local m = math.random(250,550)/10
hole.Velocity = lookvector1 * 20
local s = part.Parent:GetChildren()
for i = 1,#s do
local bprt=s[i]
if bprt.Name~=hole.Parent.Name and (bprt:IsA("BasePart") or bprt:IsA("MeshPart")) then
for r = 1,3 do
print'ding'
bprt.Velocity=Vector3.new(0,0,0)
end
end
end
end
function onTouched(hit)
print(hit,hit.Parent,hit.Parent.Parent)
if hit.Parent~=nil then
local humanoid=hit.Parent:findFirstChild("Humanoid")
local tg=hit.Parent:findFirstChild("enemy")
if humanoid~=nil and tg then
bulletImpact(script.Parent,hit)
humanoid:TakeDamage(humanoid.MaxHealth)
script.BounceHit:Play()
script.Hit:Play()
print'die'
-- elseif hit.Parent.className=="Hat" or hit.Parent.className=="Accessory" then
-- local r = Vector3.new(math.random(-1,1), math.random(0,1), math.random(-1,1))
-- local hat=hit.Parent
-- ball.BrickCleanup:clone().Parent = hit
-- hit.CanCollide=true
-- hit.Velocity = 75 * r
-- hit.Parent = game.Workspace
-- hat:remove()
wait(0.01)
ball:Destroy()
else
script.Bounce:Play()
-- blood(24)
end
end
-- connection:disconnect()
wait(6)
ball:Destroy()
end
--function blood(a)
-- for i=1,2 do
-- local s = Instance.new("Part")
-- s.Shape = 1 -- block
-- s.formFactor = 2 -- plate
-- s.Size = Vector3.new(1,.4,1)
-- s.BrickColor = BrickColor.new(21)
-- local v = Vector3.new(math.random(-1,1), math.random(0,1), math.random(-1,1))
-- s.CFrame = CFrame.new(ball.Position + v, v)
-- s.BrickColor = BrickColor.new(a)
-- if a==21 then
-- ball.BrickCleanup:clone().Parent = s
-- s.BrickCleanup.Disabled = false
-- s.Velocity = 15 * v
-- else
-- s.Velocity = 45 * v
-- ball.BrickCleanup2:clone().Parent = s
-- s.BrickCleanup2.Disabled = false
-- end
-- s.Parent = game.Workspace
-- wait(3)
-- s:Destroy()
-- end
--end
connection = ball.Touched:connect(onTouched)
wait(5)
ball:remove()
The problem is that the “hit” follows the lookVector of the bullet, but doesn’t “rotate” at all. I know it’s confusing for you and me, but here’s a diagram of how I could want it to work:
If someone could possibly recreate this, please provide me with some example code that makes it work.