How to prevent floating blood parts?

Hello scripters and developers of all kinds,

I have a problem where I have a blood system I created, and when I take damage, the blood goes up in all different directions. And I wanted to make the blood raycast distance shorter, heres an example of what happens:
real

and I want it to either:

Delete if its not touching anything
or
Position itself to the ground

heres my script. Its a little janky but it works:

game.Players.PlayerAdded:Connect(function(plr)
	local Folder = Instance.new("Folder", game.Workspace)
	Folder.Name = "BloodFolder"
	plr.CharacterAdded:Connect(function(char)
		print(char.Name)
		
		local hum = char:FindFirstChildOfClass("Humanoid")
		local oldHealth = hum.Health
		
		hum.HealthChanged:Connect(function()
			
			
			local humanoidRoot = char:WaitForChild("HumanoidRootPart")
			local rayDirection = Vector3.new(math.random(-120, 120),math.random(-120, 120),math.random(-120, 120))
			
			local raycastparams = RaycastParams.new()
			raycastparams.FilterDescendantsInstances = {char, Folder:GetChildren()}
			raycastparams.FilterType = Enum.RaycastFilterType.Blacklist
			local raycastResult = workspace:Raycast(humanoidRoot.Position, rayDirection, raycastparams)
			
			--blood sizes
			local size1 = Vector3.new(3, 0.34, 3)
			local size2 = Vector3.new(5, 0.34, 5)
			local size3 = Vector3.new(6.5, 0.34, 6.5)
			
			local random = math.random(1,3)
			
			if raycastResult then

				local blood = game.ServerStorage.BloodPart:Clone()
				local hitPart = raycastResult.Instance
				
				blood.CFrame = CFrame.new(raycastResult.Position)
				blood.CFrame = (CFrame.new(raycastResult.Position, raycastResult.Position + raycastResult.Normal) * CFrame.new(-blood.Size.X / 2,-blood.Size.Y / 2,0))* CFrame.Angles(math.rad(90),0,0)
				blood.Parent = Folder
				
				local tweenservice = game:GetService("TweenService")
				-- create size with tweenservice
				if random == 1 then
					local info = TweenInfo.new(5,Enum.EasingStyle.Circular, Enum.EasingDirection.Out,0,false,0.1)
					local goal = {Size = size1}
					local expand = tweenservice:Create(blood,info,goal)
					expand:Play()
				end
				if random == 2 then
					local info2 = TweenInfo.new(5,Enum.EasingStyle.Circular, Enum.EasingDirection.Out,0,false,0.1)
					local goal2 = {Size = size2}
					local expand2 = tweenservice:Create(blood,info2,goal2)
					expand2:Play()
				end
				if random == 3 then
					local info3 = TweenInfo.new(5,Enum.EasingStyle.Circular, Enum.EasingDirection.Out,0,false,0.1)
					local goal3 = {Size = size3}
					local expand3 = tweenservice:Create(blood,info3,goal3)
					expand3:Play()
				end
			end
		end)
	end)
end)

Anything helps! : D

2 Likes

I think you code work fine have you checked there are no Transparency part there?

No there arent any transparent parts anywhere. I have moving objects, and they only connect to what the raycast has positioned it to. And I want to always make sure every frame it is never floating, and its on an object.

Put this local rayDirection = Vector3.new(math.random(-10, 10),math.random(-10, 10),math.random(-10, 10)) instead of local rayDirection = Vector3.new(math.random(-120, 120),math.random(-120, 120),math.random(-120, 120)), also for more randomness i recommend using Random.new():NextNumber(-10, 10)