Ok so i have made a gun script. This is just the gunclient but it is this script that is mixing with the damage. The only thing thoe is that this gun can only damage npcs and not players. When i test it out on npcs they die but when i test it in real game with real players it doesn't take any damage at all. My game is in R6
Here is the script:
local remotes = game:GetService("ReplicatedStorage"):WaitForChild("GunRemotes")
local fireProjectileEvent = remotes:WaitForChild("FireProjectile")
local reloadEvent = remotes:WaitForChild("Reload")
local plrs = game:GetService("Players")
local ts = game:GetService("TweenService")
local debris = game:GetService("Debris")
local http = game:GetService("HttpService")
--[[function logHit(pos)
local part = Instance.new("Part")
part.Transparency = 0.1
part.Material = Enum.Material.Neon
part.Anchored = true
part.CFrame = CFrame.new(pos)
part.Parent = workspace
end]]
function shootProjectile(plr,emitter,endPositionData,hitData)
local gunSettings = emitter:WaitForChild("GunSettings")
if not gunSettings then
warn("No gun settings.")
return
else
gunSettings = require(gunSettings)
end
local ammo = emitter:FindFirstChild("ServerAmmo")
if not ammo then
ammo = Instance.new("IntValue")
ammo.Name = "ServerAmmo"
ammo.Value = 2220 -- Enough until they have to reload
ammo.Parent = emitter
end
if ammo.Value > 0 then
local startCFrame = CFrame.new(emitter.CFrame.p)
local newProjectileData
local totalDamage = 0
local function doProjectile(endPos, hit)
local charPos = plr.Character:GetPrimaryPartCFrame().p
local ray = Ray.new(charPos,(endPos-charPos).unit*gunSettings.MaxRange)
local ignores = {}
--[[for i, radplr in pairs(plrs:GetPlayers()) do
if radplr ~= plr then
if radplr.Character then
local radDet = plr.Character:FindFirstChild("RadiusDetector")
if radDet then
table.insert(ignores, radDet)
end
end
end
end]]
ignores[1] = plr.Character
ignores[2] = workspace:WaitForChild("Projectiles")
ignores[3] = workspace:FindFirstChild("RadiusDetectors")
local otherHit,pos = workspace:FindPartOnRayWithIgnoreList(ray, ignores, false,false)
if typeof(newProjectileData) == "table" then
table.insert(newProjectileData,pos)
else
newProjectileData = pos
end
local distance = (endPos-emitter.CFrame.p).magnitude
local char
local victimPlr
if hit then
if hit.Parent:FindFirstChild("Humanoid") then
char = hit.Parent
elseif hit.Parent.Parent:FindFirstChild("Humanoid") then
char = hit.Parent.Parent
else
for i, checkplr in pairs(game:GetService("Players"):GetPlayers()) do
if checkplr.Character then
if hit:IsDescendantOf(checkplr.Character) then
victimPlr = checkplr
char = checkplr.Character
end
end
end
end
end
if not victimPlr then
victimPlr = plrs:GetPlayerFromCharacter(char)
end
if char then
local damage = gunSettings.Damage
local saber = char:FindFirstChildWhichIsA("Tool")
if saber and not saber.Name:lower():find("saber") then
saber = nil
end
if saber then
local blocking = saber:FindFirstChild("Blocking")
if not blocking or blocking.Value == false then
saber = nil
end
end
if saber then
damage = 0
playSound(saber.Configuration.Sounds.Block,saber.Emitter)
elseif victimPlr then
if victimPlr.Team == plr.Team then
damage = 0
else
if hit.Name == "Head" or hit.Parent.Name == "Head" then
damage = damage*2
elseif string.find(hit.Name,"LeftArm") or string.find(hit.Parent.Name,"RightArm") then
damage = damage*.3
elseif string.find(hit.Name,"LeftLeg") or string.find(hit.Parent.Name,"RightLeg") then
damage = damage*.34
elseif hit.Name == "Torso" then
damage = damage*1.1
elseif hit.Name == "Torso" or hit.Parent.Name == "Torso" then
damage = damage*1.25
elseif hit.Name == "Torso" or hit.Parent.Name == "Torso" then
damage = damage*1.25
end
end
else
local damage = gunSettings.Damage
if hit.Name == "Head" or hit.Parent.Name == "Head" then
damage = damage*2
elseif string.find(hit.Name,"RightArm") or string.find(hit.Parent.Name,"LeftArm") then
damage = damage*.3
elseif string.find(hit.Name,"RightLeg") or string.find(hit.Parent.Name,"LeftLeg") then
damage = damage*.34
elseif hit.Name == "Torso" then
damage = damage*1.1
elseif hit.Name == "Torso" or hit.Parent.Name == "Torso" then
damage = damage*1.25
elseif hit.Name == "Torso" or hit.Parent.Name == "Torso" then
damage = damage*1.25
end
end
local canDamage = true
if victimPlr then
if gunSettings.CanTeamKill or victimPlr.Team ~= plr.Team then
canDamage = true
else
canDamage = true
end
end
if (victimPlr and (victimPlr.Team ~= plr.Team or victimPlr.Team.Name == "Civilian")) or gunSettings.CanTeamKill or true then
local hum = char:WaitForChild("Humanoid")
if hum.Health > 0 then
hum:TakeDamage(damage)
if hum.Health <= 0 then
local leaderstats = plr:FindFirstChild("leaderstats")
if leaderstats then
local kills = leaderstats:FindFirstChild("Kills") or leaderstats:FindFirstChild("KOs")
if kills then
kills.Value = kills.Value + 1
end
end
end
if damage == 0 then
damage = "Blocked!"
else
totalDamage = totalDamage + damage
end
else
damage = "Dead!"
end
end
end
end
if typeof(endPositionData) == "table" then
newProjectileData = {}
for i, pos in pairs(endPositionData) do
doProjectile(pos,hitData[i])
end
else
doProjectile(endPositionData, hitData)
end
ammo.Value = ammo.Value - 1
if totalDamage ~= 0 then
fireProjectileEvent:FireClient(plr,"HitIndicator",totalDamage)
end
fireProjectileEvent:FireAllClients("RecieveProjectile",plr,emitter,newProjectileData,hitData)
--[[if pos then
if distance < 5 then
fireProjectileEvent:FireAllClients("RecieveProjectile",plr,emitter,endPos,orTick)
else
fireProjectileEvent:FireAllClients("RecieveProjectile",plr,emitter,pos,orTick)
end
else
fireProjectileEvent:FireAllClients("RecieveProjectile",plr,emitter,endPos,orTick)
end]]
end
end
function playSound(sound,parent)
if sound then
local soundClone = sound:Clone()
soundClone.Parent = parent
soundClone:Play()
debris:AddItem(soundClone,soundClone.TimeLength)
end
end
fireProjectileEvent.OnServerEvent:Connect(function(plr,mode,emitter,endPos,hitData)
if mode == "FireProjectile" then
if emitter:IsDescendantOf(plr.Character) then
shootProjectile(plr,emitter,endPos,hitData)
end
end
end)
reloadEvent.OnServerEvent:Connect(function(plr)
if plr.Character and plr.Character:WaitForChild("Humanoid").Health > 0 then
local gun = plr.Character:FindFirstChildWhichIsA("Tool")
if gun then
local ammo = gun:FindFirstChild("ServerAmmo")
if not ammo then
ammo = Instance.new("IntValue")
ammo.Name = "ServerAmmo"
ammo.Value = 1000 -- Enough until they have to reload
ammo.Parent = gun.Emitter
end
local gunSettings = gun:FindFirstChild("Emitter") and gun.Emitter:FindFirstChild("GunSettings") and require(gun.Emitter.GunSettings)
if ammo and gunSettings then
ammo.Value = gunSettings.MaxAmmo
end
end
end
end)
function printLogo()
print("--------------------------------------------------------")
print(" no no no no")
print(" KERMO ORACVE LEON ")
print(" KERMO ORACVE LEON ")
print(" KERMO ORACVE LEON ")
print(" OK ")
print(" urmomsucks ")
print("--------------------------------------------------------")
end
printLogo()

4 comments
Errors?
Nope none...
Maybe try to only show the part where the damage taking actually happens
Oh thats right