IT would function if it was in the ServerScriptService but that would have more problems and I sort of need to figure out how the instance can properly detect the “Humanoid” whilst avoiding the fact I need to put it in ServerScriptService.
The “GunServer” is where the script is located Inside the tool.
if Result.Instance.Name == "Head" then
print("Hit through head")
Humanoid.Health -= Damage * HeadshotBonus
else
print("Hit other thing")
Humanoid.Health -= Damage
end
It does not print anything? We can go from there once we know this.
That is what I am assuming is what is deducting the health.
Sometimes Result.Instance.Parent is unreliable if the raycast happens to hit an Accessory, so I recommend you replace it with this:
local Model = Result.Instance:FindFirstAncestorWhichIsA("Model")
if Model == nil then return end
local Humanoid = Model:FindFirstChildWhichIsA("Humanoid")
Sorry for the late reply, but after re-reading the script in the main topic I’m noticing you’re using Enum.RaycastFilterType.Include instead of Enum.RaycastFilterType.Exclude for the RayParams, which will result in the raycast only being able to hit the character who shot the raycast themselves
I’m unsure as to what’s causing the raycast to slow down though
You need to convert it to a unit vector first before multiplying the gun range like so:
local Direction = (MousePosition - Gun.Muzzle.Attachment.WorldPosition).Unit * GunRange
I also think that the attachment’s WorldPosition meeds to be used instead of its Position since WorldPosition uses world space and Position uses object space in attachments