Raycast blacklist not working?

I want to make a system where a player is able to finish off another player. Unfortunately when I make the raycast it thinks I’m the character and queues the animation.

I tried filtering out the local character model, but it just ignores it.

Code
local runService = game:GetService("RunService")
local replicatedStorage = game:GetService("ReplicatedStorage")
local userInputService = game:GetService("UserInputService")
local players = game:GetService("Players")

local localPlayer = players.LocalPlayer
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
local mouse = localPlayer:GetMouse()

local remotes = replicatedStorage:WaitForChild("remotes")

local punch = remotes:WaitForChild("punch")
local finish = remotes:WaitForChild("finish")

local humanoid = character:WaitForChild("Humanoid")

local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

local locked = false

local target

local swingNumber = 1

-- Anims
local anims = script:WaitForChild("Anims")
local weaponless = anims:WaitForChild("weaponless")
local leftPunch = weaponless:WaitForChild("leftPunch")
local rightPunch = weaponless:WaitForChild("rightPunch")
local lay = weaponless:WaitForChild("lay")
-- Anims

userInputService.InputBegan:Connect(function(i)
	if i.UserInputType == Enum.UserInputType.MouseButton3 then
		if mouse.Target.Parent:IsA("Model") and mouse.Target.Parent:FindFirstChild("Humanoid") then
			target = mouse.Target
			locked = true
			
		elseif locked then
			locked = false
		end
	end
	if i.KeyCode == Enum.KeyCode.E then
		finish:FireServer()
		
		local rayParams = RaycastParams.new()
		rayParams.FilterDescendantsInstances = {humanoidRootPart.Parent}
		local raycast = workspace:Raycast(humanoidRootPart.Position,Vector3.new(0,-10,0))
		
		if raycast then
			local part = raycast.Instance
			
			if part.Parent:IsA("Model") and part.Parent:FindFirstChild("Humanoid") then
				local anim = humanoid:LoadAnimation(lay)
				anim:Play()
			end
		end
	end
end)

mouse.Button1Down:Connect(function()
	if swingNumber == 1 then
		punch:FireServer(1)
		swingNumber = 0
		local anim = humanoid:LoadAnimation(leftPunch)
		anim:Play()
		coroutine.wrap(function()
			wait(1)
			swingNumber = 2
		end)();
	elseif swingNumber == 2 then
		punch:FireServer(2)
		swingNumber = 0
		local anim = humanoid:LoadAnimation(rightPunch)
		anim:Play()
		coroutine.wrap(function()
			wait(1)
			swingNumber = 1
		end)();
	end
end)

runService.RenderStepped:Connect(function()
	    workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
	    workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame:Lerp(CFrame.new(humanoidRootPart.Position+Vector3.new(0,20,0))*CFrame.Angles(math.rad(-90),0,0),0.2)
	
	if locked == false then
		humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position,Vector3.new(mouse.Hit.Position.X,humanoidRootPart.Position.Y,mouse.Hit.Position.Z))
	else
		if target.Parent.stunned.Value == false then
		   local hrp = target.Parent:WaitForChild("HumanoidRootPart")
		
			humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position,Vector3.new(hrp.Position.X,humanoidRootPart.Position.Y,hrp.Position.Z))
		else
			locked = false
		end
	end
end)
1 Like

Either I didn’t get enough sleep or you didn’t pass your raycast parameters when you did the actual raycast:

local raycast = workspace:Raycast(humanoidRootPart.Position,Vector3.new(0,-10,0), rayParams)

4 Likes