Raycast not detecting character

I’m trying to use a ray to detect if a character is under the player’s character when stomping, but it doesn’t seem to be detecting anything. I tried using FindPartOnRayWithIgnoreList but even that didn’t work.

Server script:

game.ReplicatedStorage.Remotes.Stomp.OnServerEvent:Connect(function(p,char)
	local disc
	local cantouch
	local ee = Instance.new("StringValue")
	ee.Name = "ee"
	ee.Parent = char.Parent
	game:GetService("Debris"):AddItem(ee,2)
	print("3")
	wait(1)
	local ray = Ray.new(char.LeftFoot.Position,char.HumanoidRootPart.Position-Vector3.new(0,10,0))
	local chars = {}
	for i, v in pairs(workspace:GetChildren()) do
		if v:FindFirstChild("Humanoid") and v ~= char then
			print(v.Name)
			table.insert(chars,v)
		end
	end
	local part = workspace:FindPartOnRayWithWhitelist(ray,chars)
	if part then
		print(part.Name.." e "..part.ClassName)
		if part.Parent:FindFirstChild("Humanoid") and part.Parent:FindFirstChild("Ragdolled") and not cantouch then
			print("2")
			print("1")
			spawn(function()
				print("a")
				cantouch = true
				local stomped = false
				if not part.Parent:FindFirstChild("Stomped") then
					local e = Instance.new("StringValue")
					e.Name = "Stomped"
					e.Parent = part.Parent
				else
					stomped = true
				end
				local new = Instance.new("Sound")
				new.SoundId = "rbxassetid://2174933428"
				new.Volume = 1
				new.Parent = part.Parent.UpperTorso
				new:Play()
				local clone = game.ReplicatedStorage.Other.Blood:Clone()
				clone.Enabled = true
				clone.Parent = char.LeftFoot
				wait(.1)
				clone.Enabled = false
				wait(4)
				if stomped == false then
					game.Players[part.Parent.Name]:LoadCharacter()
				end
				disc = true
			end)
		end
	end
end)

Any help would be appreciated. :slightly_smiling_face:

1 Like

Your Ray is not pointing where you think it is! The second argument to Ray.new is the direction of the Ray, not the end point. Try passing Vector3.new(0,-10,0) as the second argument instead :blush:

4 Likes