Player = game.Players.LocalPlayer
Gun = script.Parent
FireSound = Gun.ShootSound
LoadSound = Gun.ReloadSound
mouse = Player:GetMouse()
enabled = true
Gun.Ammo.Value = 5
MaxAmmo = 5
function e()
script.Parent.CanReload.Value = true
end
function u()
script.Parent.CanReload.Value = false
end
function Shoot()
function Damage(Part)
local Humanoid = Part.Parent:FindFirstChild("Humanoid")
local target = game.Players:GetPlayerFromCharacter(Part.Parent)
if target.TeamColor == Player.TeamColor then -- Checks if they're not on the same team, and if it's not the own player
Humanoid:TakeDamage(0)
else
if target ~= Player then
Humanoid:TakeDamage(5)
end
end
end
if Gun.Ammo.Value > 0 and enabled == true then
Gun.Ammo.Value = Gun.Ammo.Value - 1
enabled = false
Bullet = Instance.new("Part", game.Workspace)
Gun.GripForward = Vector3.new(-0.975, -0.223, -0.02)
game.Debris:AddItem(Bullet, 2)
Bullet.Shape = "Ball"
Bullet.Size = Vector3.new(0.2,0.2,0.2)
Bullet.TopSurface = "Smooth"
Bullet.BottomSurface = "Smooth"
Bullet.Transparency = 1
Bullet.BrickColor = BrickColor.new("Dark stone grey")
Bullet.CanCollide = false
Bullet.CFrame = Gun.Handle.CFrame
Bullet.CFrame = CFrame.new(Bullet.Position,mouse.Hit.p)
v = Instance.new("BodyVelocity", Bullet)
v.velocity = Bullet.CFrame.lookVector *900
v.maxForce = Vector3.new(math.huge, math.huge, math.huge)
FireSound:Play()
Shell = Instance.new("Part", game.Workspace)
Shell.TopSurface = "Smooth"
Shell.BottomSurface = "Smooth"
Shell.Size = Vector3.new(.1,.1,.1)
game.Debris:AddItem(Shell, 0.8)
Shell.CFrame = Gun.Handle.CFrame *CFrame.new(0, -.5, -.3)
Bullet.Touched:connect(Damage)
Light = Instance.new("PointLight", Gun)
wait(.1)
Light:Destroy()
Gun.GripForward = Vector3.new(-0.975, 0, -0.02)
wait()
enabled = true
end
end
function Reload(key)
key = key:lower()
if key == 'r' then
if enabled == true and Gun.Ammo.Value < MaxAmmo and script.Parent.CanReload.Value == true then
LoadSound:Play()
wait(LoadSound.TimeLength)
Gun.Ammo.Value = MaxAmmo
end
end
end
script.Parent.Equipped:connect(e)
script.Parent.Unequipped:connect(u)
mouse.KeyDown:connect(Reload)
Gun.Activated:connect(Shoot)
This script is a modified version of a "fixed" script by another user of ScriptingHelpers (I posted the old version in another question). The non-team kill aspect of it finally works, but I need it to be able to kill humanoids that aren't related to players, but it won't do that. It just gives an error about not being able to find the Target. Someone help?

2 comments
All that does is get rid of the error messages, but besides that it doesn't change a thing. I need it to be able to damage non-player related humanoids which it doesn't
I got a working version of it