Hello, as the title states, I want a bullet to damage NPCs and players, but only damages players, despite NPCs humanoid having the same name. All of this is done on the client, but send the damage to the server to damage. Here is the client code:
local ts = game:GetService("TweenService")
game.Workspace.Events.Gun.OnClientEvent:Connect(function(handle) -- handle instance of the gun
if game.Players.LocalPlayer.Name == handle.Parent.Parent.Name then
local part = game.ReplicatedStorage.BlackHole:Clone()
game:GetService("Debris"):AddItem(part,20)
part.Size = Vector3.new(1,1,1)
part.Name = "Handle" -- in case things interfered because of name
part.Parent = game.Workspace
local v = Instance.new("BodyVelocity")
v.Parent = part
v.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
v.Velocity = game.Players.LocalPlayer:GetMouse().Hit.LookVector * 120
part.Position = handle.Position
part.Anchored = false
coroutine.wrap(function()
ts:Create(part,TweenInfo.new(0.6,Enum.EasingStyle.Quint,Enum.EasingDirection.InOut,0,false,0),{Size = Vector3.new(15,15,15)}):Play()
part.Touched:Connect(function(h)
local attackdebounce = false
if h.Parent then
local hum = h.Parent:FindFirstChildOfClass("Humanoid")
if hum and hum.Health > 0 then
if hum.Parent.Name ~= handle.Parent.Parent.Name then
if dbb == false then
dbb = true
game.Workspace.Events.Gun:FireServer(hum)
wait(0.5)
dbb = false
end
end
end
end
end)
end)
end
end)
It doesnt detect touched on the NPC though, I already use take damage on the server when i fire the humanoid instance to the server. as for the wall, the bullet size increase after being fired, and is large enough to hit no matter what. It hits player models, but not NPCs
You will need to show the onServerEvent code also i found out that you are creating a listener (Part.Touched) but not deleting it . That could lag your game
local ts = game:GetService("TweenService")
game.Workspace.Events.Gun.OnClientEvent:Connect(function(handle) -- handle instance of the gun
if game.Players.LocalPlayer.Name ~= handle.Parent.Parent.Name then return end
local part = game.ReplicatedStorage.BlackHole:Clone()
game:GetService("Debris"):AddItem(part,20)
part.Size = Vector3.new(1,1,1)
part.Name = "Handle" -- in case things interfered because of name
part.Parent = workspace
local v = Instance.new("BodyVelocity")
v.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
v.Velocity = game.Players.LocalPlayer:GetMouse().Hit.LookVector * 120
v.Parent = part
part.Position = handle.Position
part.Anchored = false
coroutine.wrap(function()
ts:Create(part,TweenInfo.new(0.6,Enum.EasingStyle.Quint,Enum.EasingDirection.InOut,0,false,0),{Size = Vector3.new(15,15,15)}):Play()
part.Touched:Connect(function(h)
local attackdebounce = false
local char = h.Parent
local hum = char:FindFirstChildOfClass("Humanoid")
print(hum, hum.Health, char.Name, dbb)
if not hum or hum.Health <= 0 or char.Name == handle.Parent.Parent.Name or dbb then return end
dbb = true
game.Workspace.Events.Gun:FireServer(hum)
wait(0.5)
dbb = false
end)
end)()
end)