local Tool = script.Parent
local Configs = Tool.Configs
local gunconfigs = Tool.GunConfigs
local reloading = gunconfigs.Reloading
local events = Tool.Events
local mouse
local MaxClipSize = gunconfigs.Clip:Clone()
MaxClipSize.Name = "MaxClipSize"
MaxClipSize.Parent = gunconfigs
local MaxMagSize = gunconfigs.Mag:Clone()
MaxMagSize.Name = "MaxMagSize"
MaxMagSize.Parent = gunconfigs
gunconfigs.Clip.Changed:connect(function(value)
if value == 0 then
reload()
end
end)
function runsound(sound)
local ranvol = math.random(70, 90)
ranvol = ranvol / 10
sound.Volume = ranvol
sound:Play()
end
function reload()
if gunconfigs.Clip.Value < MaxClipSize.Value then
if gunconfigs.Mag.Value > 0 then
events.Reload:FireClient(game.Players[Tool.Parent.Name],"Reload","Reloading")
reloading.Value = true
runsound(gunconfigs.Reload)
wait(Configs.ReloadTime.Value)
local clipsize = MaxClipSize.Value - gunconfigs.Clip.Value
if gunconfigs.Mag.Value >= clipsize then
gunconfigs.Clip.Value = gunconfigs.Clip.Value + clipsize
gunconfigs.Mag.Value = gunconfigs.Mag.Value - clipsize
else
gunconfigs.Clip.Value = gunconfigs.Clip.Value + gunconfigs.Mag.Value
gunconfigs.Mag.Value = 0
end
reloading.Value = false
events.Shoot:FireClient(game.Players[Tool.Parent.Name],"StopShooting")
else
runsound(gunconfigs.EmptyClip)
if Tool.Parent.Name ~= "Backpack" then
events.Shoot:FireClient(game.Players[Tool.Parent.Name],"StopShooting")
end
end
else
print("Why are you trying to reload a full clip?")
end
end
spawn(function()
while true do wait(.05)
if game.Players:FindFirstChild(Tool.Parent.Name) then
events.GetMouse:FireClient(game.Players[Tool.Parent.Name])
end
end
end)
events.GetMouse.OnServerEvent:connect(function(player,v) mouse = v end)
function shoot()
events.Shoot:FireClient(game.Players[Tool.Parent.Name],"StartShooting")
runsound(gunconfigs.Fire)
local bullet = Instance.new("Part", workspace)
bullet.Touched:connect(function(hit)
if hit.Parent~=Tool.Parent and hit.Parent~=Tool then
--damage bullet
if hit.Parent:FindFirstChild("Zombie") and hit.Parent.Zombie:IsA("Humanoid") and not hit.Parent.Zombie:FindFirstChild("DamageTag") and hit.Parent.Zombie.Health >= Configs.BulletDamage.Value then
if hit.Name == "Head" then
hit.Parent.Zombie:TakeDamage(Configs.BulletDamage.Value*2)
else
hit.Parent.Zombie:TakeDamage(Configs.BulletDamage.Value)
end
if hit.Parent.LastAttacker.Value == "" then
for i,v in pairs (hit.Parent.Attackers:GetChildren()) do
if v.Name == Tool.Parent.Name then
v:Destroy()
end
end
hit.Parent.LastAttacker.Value = Tool.Parent.Name
else
if not hit.Parent.Attackers:FindFirstChild(Tool.Parent.Name) and hit.Parent.LastAttacker.Value ~= Tool.Parent.Name then
local attacktag = Instance.new("Folder",hit.Parent.Attackers)
attacktag.Name = hit.Parent.LastAttacker.Value
end
hit.Parent.LastAttacker.Value = Tool.Parent.Name
end
local cash = game.Players[Tool.Parent.Name].leaderstats.Cash
cash.Value = cash.Value + Configs.CashPerHit.Value
hit.Parent.LastHit.Value = hit.Name
print(hit.Parent.Zombie.Health)
local tag = Instance.new("Folder",hit.Parent.Zombie)
tag.Name = "DamageTag"
game.Debris:AddItem(tag,.2)
end
end
end)
game.Debris:AddItem(bullet, 2)
bullet.Shape = "Ball"
bullet.Size = Vector3.new(.5 ,.5 ,.5)
bullet.BrickColor = BrickColor.new("Really black")
bullet.CanCollide = false
bullet.CFrame = Tool.BulletSpawn.CFrame
bullet.CFrame = CFrame.new(bullet.Position, mouse)
local bulmesh = Instance.new("SpecialMesh", bullet)
bulmesh.MeshType = "Sphere"
bulmesh.Scale = Vector3.new(.2,.2,.8)
local shell = bullet:Clone()
shell.BrickColor = BrickColor.new("New Yeller")
shell.CFrame = Tool.ShellDrop.CFrame
shell.Parent = Tool
game.Debris:AddItem(shell,5)
shell.CanCollide = true
local v = Instance.new("BodyVelocity", bullet)
v.velocity = bullet.CFrame.lookVector * (Configs.BulletSpeed.Value*60)
v.maxForce = Vector3.new(math.huge, math.huge, math.huge)
end
function noAmmo()
runsound(gunconfigs.EmptyClip)
events.Reload:FireClient(game.Players[Tool.Parent.Name],"Error")
end
function equipped()
--print("e")
end
local shooting = false
function activated()
shooting = true
while shooting == true do wait(Configs.ShootingSpeed.Value/10)
if reloading.Value == false then
if gunconfigs.Clip.Value >= 1 then
gunconfigs.Clip.Value = gunconfigs.Clip.Value - 1
shoot()
elseif gunconfigs.Mag.Value > 0 then
reload()
else
noAmmo()
end
end
end
if reloading.Value == false then
events.Shoot:FireClient(game.Players[Tool.Parent.Name],"StopShooting")
end
shooting = false
end
function deactivated()
shooting = false
wait(.05)
if reloading.Value == false then
events.Shoot:FireClient(game.Players[Tool.Parent.Name],"StopShooting")
end
end
function unequipped()
--print("u")
end
events.Reload.OnServerEvent:connect(function()
if gunconfigs.Mag.Value > 0 then
reload()
else
noAmmo()
end
end)
Tool.Equipped:connect(equipped)
Tool.Activated:connect(activated)
Tool.Deactivated:connect(deactivated)
Tool.Unequipped:connect(unequipped)
COMMUNITY QUESTION
My gun script doesn't kill actual people in my game, needing a way to fix it?!
1 answer
I think the problem in your script would be this part:
if hit.Parent:FindFirstChild("Zombie") and hit.Parent.Zombie:IsA("Humanoid") and not hit.Parent.Zombie:FindFirstChild("DamageTag") and hit.Parent.Zombie.Health >= Configs.BulletDamage.Value then
if hit.Name == "Head" then
hit.Parent.Zombie:TakeDamage(Configs.BulletDamage.Value*2)
else
hit.Parent.Zombie:TakeDamage(Configs.BulletDamage.Value)
end
It only damages Zombies because that's all you set it to hit which you of course know. A solution would be putting an or in the if statement that also hits Humanoids like this:
if hit.Parent:FindFirstChild("Zombie") or hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Zombie:IsA("Humanoid") and not hit.Parent.Zombie:FindFirstChild("DamageTag") and hit.Parent.Zombie.Health >= Configs.BulletDamage.Value or hit.Parent.Humanoid.Health >= Configs.BulletDamage.Value then
if hit.Name == "Head" then
hit.Parent.Zombie:TakeDamage(Configs.BulletDamage.Value*2)
hit.Parent.Humanoid:TakeDamage(Configs.BulletDamage.Value*2)
else
hit.Parent.Zombie:TakeDamage(Configs.BulletDamage.Value)
hit.Parent.Humanoid:TakeDamage(Configs.BulletDamage.Value)
end
I'm not 100% sure if this will work, but to my knowledge it should help a bit.
1 comment
0
I had to edit this a few times because I saw a few issues in my own script.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
It's been a while since I've created this gun & once I came back to it, I realized I made it where it only kills Zombies... I hope you can help guys.
Add a heckin description