It printed “nil Model True” which is odd since swords with the same type of code work just fine.
Are you certain the Humanoid is placed correctly? If it’s not finding the Humanoid then you must’ve placed it incorrectly? How does the model look in the explorer
Maybe your layout to the NPCs character is different to the players can you show us the explorer view of ur NPC. Could be the line where you check if the parent contains a humanoid Returns nil idk
I attached an image, I got an idea with touched was being counted in one of the models instead of the HumanoidRootPart, so I tried adding a check, but instead it gave nil Stuff True, Stuff is the parent of the NPC
Coudl it be that the Touched event is hitting whatever is in those 3 models?
I added a check for that, but I can try some things and get back to you.
Seems as you going to need to some ‘smart’ checking before we actually check for humanoid
(Sorry about last reply misunderstood the question )
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
if h:IsA("BasePart") then
local char = h.Parent
local hum = char:FindFirstChildOfClass("Humanoid")
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)()
end)
Maybe try this for your touched event?
part.Touched:Connect(function(h)
local attackdebounce = false
local char = h.Parent
local hum = char:FindFirstChildOfClass("Humanoid") or char.Parent:FindFirstChildOfClass("Humanoid")
print(hum, 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)
why is there something inside the humanoid
This is happening because the Touched event only detects if the object that touched has touched due to the effect of the physics engine. Tweening or setting the CFrame or position will not make the Touched event fire.
Your system of the gun itself is bad and easily exploitable. I recommend using FastCast module for projectile-based weapons.
Also it is not guaranteed for the parent of the part hit to be a character, maybe the parent of a part is a Model which is inside the character? In that case the script will consider it as not a character and thus not damage the NPC. If that is the case then you need to put some sort of label inside these Models present in the character so the script can know that the actual character is the parent of this Model.