For some reason its just not getting a raycastresult at all and I have no idea why unless I literally shove the handle inside the NPC
--Services
local Players = game:GetService("Players")
local Debris = game:GetService("Debris")
--References
local Tool = script.Parent
local FireEvent = Tool.FireGun
local Handle = Tool.Handle
local Gunshot = Handle.Gunshot
local Character = nil
local Player = nil
local RayParams = RaycastParams.new()
RayParams.FilterType = Enum.RaycastFilterType.Blacklist
--Get Character and Player
Tool.Equipped:Once(function()
Character = Tool.Parent
Player = Players:GetPlayerFromCharacter(Character)
RayParams.FilterDescendantsInstances = {Character, Handle}
end)
FireEvent.OnServerEvent:Connect(function(Fired, MousePos)
--Check the shooter is our player and the tool is equipped
if Fired ~= Player then Fired:Kick() return elseif Tool.Parent ~= Character then Player:Kick() return end
Gunshot:Play()
local Muzzle = Instance.new("PointLight")
Muzzle.Color = Color3.fromRGB(255, 235, 7)
Muzzle.Brightness = 2
Muzzle.Range = 17
Muzzle.Parent = Handle
Debris:AddItem(Muzzle, .2)
local Result = workspace:Raycast(Handle.Position, MousePos.Position, RayParams)
if not Result then return end
print("valid result")
if Result.Instance.Parent then
local Humanoid = Result.Instance.Parent:FindFirstChild("Humanoid")
if Humanoid then
Humanoid:TakeDamage(30)
end
end
end)