So ive been stuck on this for almost 2 weeks, Why does my raycast doesnt return its result if it hits players’ character when i parented the result’s instance in to a players’ character
local tool = script.Parent
local laserFireEvent = tool:WaitForChild("LaserFire")
local laserFolder = game.Workspace.Lasers
local Animation = tool:WaitForChild("Recoil")
local range = 100
local sound = tool:WaitForChild("DaRevolver")
--local function CreateBeam(origin, direction)
--local midpoint = origin + direction/2
--local part = Instance.new("Part")
---part.Parent = laserFolder
--part.Anchored = true
--part.CanCollide = false
--part.Material = Enum.Material.Neon
--part.BrickColor = BrickColor.new("New Yeller")
--part.Transparency = 1
--part.CFrame = CFrame.new(midpoint, origin)
--part.Size = Vector3.new(.1, .1, direction)
--wait()mc
--part:Destroy()
--end
laserFireEvent.OnServerEvent:Connect(function(player, mousePos, originPos)
local char = tool.Parent
local hum = char.Humanoid
local animationtrack = hum:LoadAnimation(Animation)
animationtrack:Play()
sound:Play()
local raycastparams = RaycastParams.new()
raycastparams.FilterDescendantsInstances = {player.Character}
raycastparams.FilterType = Enum.RaycastFilterType.Blacklist
local direction = (mousePos - originPos).Unit * range
local result = workspace:Raycast(originPos, direction, raycastparams)
local intersection = result and result.Position or originPos + direction
local distance = (originPos - intersection).Magnitude
local beam = Instance.new("Beam")
beam.Segments = 1
beam.Width0 = 0.2
beam.Width1 = 0.2
beam.Color = ColorSequence.new(Color3.new(0.988235, 1, 0.133333))
beam.Transparency = NumberSequence.new(1,1)
beam.Transparency = NumberSequence.new(0.9,0)
beam.Transparency = NumberSequence.new(0.8,0)
beam.Transparency = NumberSequence.new(0.5,0)
beam.Transparency = NumberSequence.new(0.9,0)
beam.Transparency = NumberSequence.new(0.9,0)
beam.FaceCamera = true
local attachment0 = Instance.new("Attachment")
local attachment1 = Instance.new("Attachment")
beam.Attachment0 = attachment0
beam.Attachment1 = attachment1
beam.Parent = workspace.Terrain
attachment0.Parent = workspace.Terrain
attachment1.Parent = workspace.Terrain
attachment0.Position = originPos
attachment1.Position = mousePos
wait()
beam:Destroy()
if result then
local charHit = game.Players:GetPlayerFromCharacter(result.Instance.Parent)
if charHit then
if charHit.TeamColor ~= player.TeamColor then
if result.Instance:IsA("BasePart") and result.Instance.Name == "Handle" and result.Instance.Parent:IsA("Accessory") then
charHit.Character.Humanoid.Health -= 100
print(result.Instance)
else
charHit.Character.Humanoid.Health -= 100
print(result.Instance)
end
end
end
end
--CreateBeam(originPos, direction)
end)