So, I am trying to integrate a tool containing a gun script with a vehicle. The problem is, I cant assign the tool to the specific gun. Line 27 is where the bullet exits out of. But since there is more than 1 vehicle, the bullets will only spawn at that gun. Here is the gun script:
enabled = false
player = game:GetService("Players").LocalPlayer
tool = script.Parent
bulletDamage = 350
on = false
mouse = player:GetMouse()
local gunIsFiring = false
local function Shoot()
if enabled == false then
gunIsFiring = true
local sound = Instance.new("Sound",workspace)
sound.SoundId = "rbxassetid://136523485"
sound:Play()
game.Debris:AddItem(sound, 2)
local bulletProjectile = Instance.new("Part", workspace)
bulletProjectile.Shape = ("Ball")
bulletProjectile.Name = ("Bullet")
game.Debris:AddItem(bulletProjectile, 5)
bulletProjectile.Size = Vector3.new(0.4, 0.4, 0.4)
local bulletProjectileM = Instance.new("SpecialMesh", bulletProjectile)
bulletProjectileM.MeshType = "Sphere"
bulletProjectileM.Scale = Vector3.new(1, 1, 1)
bulletProjectile.BrickColor = BrickColor.new("Black")
bulletProjectile.Reflectance = 0.5
bulletProjectile.TopSurface = "Smooth"
bulletProjectile.BottomSurface = "Smooth"
bulletProjectile.CFrame = game.Workspace.Coolcar.HoverV.Hole.CFrame * CFrame.new(0,0,1)
bulletProjectile.CFrame = CFrame.new(bulletProjectile.Position, mouse.hit.p)
local bulletForce = Instance.new("BodyVelocity", bulletProjectile)
bulletForce.velocity = bulletProjectile.CFrame.LookVector * 360
bulletForce.maxForce = Vector3.new(90000, 90000, 90000)
game.Debris:AddItem(bulletProjectile, 3)
local function harmPart(Part)
local splode = Instance.new("Explosion", game.Workspace)
splode.ExplosionType = "NoCraters"
splode.DestroyJointRadiusPercent = 1
splode.BlastPressure = 10
splode.BlastRadius = 5
splode.Position = bulletProjectile.Position
game.Debris:AddItem(splode, 0.1)
if Part.Parent:FindFirstChild("Humanoid") ~= nil then
Part.Parent.Humanoid.Health = Part.Parent.Humanoid.Health -(bulletDamage)
end
end
bulletProjectile.Touched:connect(harmPart)
enabled = true
wait(0.5)
enabled = false
end
end
tool.Equipped:connect(function(Mouse)
Mouse.Button1Down:connect(Shoot)
end)
tool.Unequipped:connect(function(Mouse)
end)

1 comment
If the script is inside the vehicle/gun, you can do "script.Parent" and so on to get to where you want.