The bullet wont even shoot from the correct target (EarthPart) in workspace. Why??
local Target = Mouse.Target local Dist = ((Target.Position-EarthPart.Position).magnitude) local Bullet = Create'Part'{BrickColor=BrickColor.new('New Yeller'),Parent=EarthPart,Name='Bullet',Anchored=true,CanCollide=false,Locked=true,FormFactor='Custom',Size=Vector3.new(.2,Dist,.2)} Bullet.CFrame = CFrame.new(EarthPart.Position,Target.Position) * CFrame.new(0,-Dist,0) local GunSound = Instance.new("Sound",workspace) GunSound.Pitch = 1 GunSound.Volume = 1 GunSound.Looped = false GunSound.SoundId = "rbxassetid://132456235" GunSound:Play() for i = 0,1.1 do Bullet.Transparency = Bullet.Transparency + .1 Services.run.RenderStepped:wait() end Bullet.Touched:connect(function(obj) if obj.ClassName == 'Model' then if obj:FindFirstChild('Humanoid',true) then obj.Humanoid.Health = obj.Humanoid.Health - 15 end end end) Bullet:remove()
You're setting the initial CFrame of the bullet to the specified relativity of 'EarthPart', which is fine. But when you offset the CFrame with * CFrame.new(0,-Dist,0)
then, as you can see, you offset from the Y axis - Y axis is up and down. So since your offset is a negative integer, the bullet will always spawn Dist
amount of studs under the original position.
So, i'm assuming you want to make the bullet go in front of you, yes? To do this you have to offset from the Z axis - Z axis is front and back, in relative terms. So since the offset is a negative integer, the bullet will now spawn Dist
amount of studs in front of the original position.
Bullet.CFrame = CFrame.new(EarthPart.Position,Target.Position) * CFrame.new(0,0,-Dist) --Offset on Z axis(:
If I'm not mistaken, Z is the front face when working with CFrame.
Bullet.CFrame = CFrame.new(EarthPart.Position,Target.Position) * CFrame.new(0,0,-Dist)