So for my gun only sometimes the humanoids take damage.
I added print statements so you know what happens.
game.ReplicatedStorage.Events.Fire.OnServerEvent:Connect(function(player, pos, damage, target)
print("Server Received")
local gun = player.Character:FindFirstChild("Pistol")
if gun == nil then return end
local muzzle = gun:FindFirstChild("Muzzle")
local direction = (pos - muzzle.Position)
local rayparams = RaycastParams.new()
local character = player.Character:GetChildren()
rayparams:AddToFilter(character)
rayparams:AddToFilter(gun:GetDescendants())
rayparams.FilterType = Enum.RaycastFilterType.Blacklist
muzzle.Laser:Play()
local ray = workspace:Raycast(muzzle.Position, direction, rayparams)
print("Ray on target")
if ray == nil then return end
print("Humanoid is real")
local Humanoid = ray.Instance.Parent:FindFirstChild("Humanoid")
if Humanoid == nil then return end
Humanoid.Health -= 20
print("damage taken")
end)
Here’s a video.
And a image.
Can someone tell me what’s wrong with the script