Here is the code that is supposed to damage the player:
GunEvent.OnServerEvent:Connect(function(player, BPoint, Mouse, tool)
local info = require(rep.GunModules[tool.Name])
local ignore = {player.Character, tool}
local ray = Ray.new(BPoint, (Mouse-BPoint).Unit*250)
local bullet, Position = game.Workspace:FindPartOnRayWithIgnoreList(ray, ignore, false, true)
tool.Handle.GunShot:Play()
if bullet then
local hum = bullet.Parent:FindFirstChild("Humanoid")
if bullet.Parent ~= nil and hum then
hum:TakeDamage(info.Damage)
end
end
end)
I genuinely have no idea, or even a theory as to why it’s happening. Help is mucho appreciado!
It may be because you are hitting the characters hair, which is a mesh, therefore this would return the hit parts parent as a hat, which does not contain a humanoid child.
local hum = bullet.Parent:FindFirstChild("Humanoid")
if bullet.Parent ~= nil and hum then
as @AlbertSeir has mentioned, you are hitting the player’s hat, as a fix, instead of searching just the parent of the hit object, use :FindFirstAncestorOfClass("Model") to get the hit model, then check that for the humanoid.
local info = require(rep.GunModules[tool.Name])
local ignore = {player.Character, tool}
local ray = Ray.new(BPoint, (Mouse-BPoint).Unit*250)
local bullet, Position = game.Workspace:FindPartOnRayWithIgnoreList(ray, ignore, false, true)
tool.Handle.GunShot:Play()
if bullet then
if bullet:FindFirstAncestorOfClass("Model") then
local hum = bullet:FindFirstAncestorOfClass("Model"):FindFirstChild("Humanoid")
if bullet.Parent ~= nil and hum then
hum:TakeDamage(info.Damage)
end
end
end
end)
This is very likely the issue, what I’d recommend is to make a table of all the players (with just GetPlayers) and then loop to find if the hit part is a descendant of any of the player’s characters (:IsDescendantOf()). This of course wouldn’t work on dummies tho
Alternatively, you could check if hit is a descendant of a Model (FindFirstAncestorWhichIsA or something) and then check that model for a humanoid
Edit: it would appear that as I was typing this @Kaid3n22 beat me to it with the whole findfirstancestorofclass thing
f lol