Basically i’m trying to make a gun that only damages the npcs, problem is it damages players too!
local re = script.Parent:WaitForChild("RemoteEvent")
local damage = 10
local bang = script.Parent.pistol.GunShot
re.OnServerEvent:Connect(function(player, target)
bang:Play()
if target then
local model = target.Parent
if model:FindFirstChild("Humanoid") then
for i, v in pairs(game:GetService("Players"):GetPlayers()) do
if model:FindFirstChild("Humanoid") then
if model.Name ~= v.Name then
print(model)
local hum = model:FindFirstChild("Humanoid")
hum:TakeDamage(damage)
end
end
end
end
end
end)
local Players = game:GetService("Players")--Get the "Players" Service
local re = script.Parent:WaitForChild("RemoteEvent")
local damage = 10
local bang = script.Parent.pistol.GunShot
re.OnServerEvent:Connect(function(player, target)
bang:Play()
if target then
local model = target.Parent
if model:FindFirstChild("Humanoid") then
if Players:GetPlayerFromCharacter(model) then return end --if it's not a player then continue
print(model)
local hum = model:FindFirstChild("Humanoid")
hum:TakeDamage(damage)
end
end
end)
local re = script.Parent:WaitForChild("RemoteEvent")
local damage = 10
local bang = script.Parent.pistol.GunShot
local Players = game:GetService("Players")
re.OnServerEvent:Connect(function(player, target)
bang:Play()
if (target) then
local Character = Players:GetPlayerFromCharacter(target) or Players:GetPlayerFromCharacter(target.Parent)
if (Character) then
local hum = Character:FindFirstChild("Humanoid")
hum:TakeDamage(damage)
end
end
end)