Issue with adding Vector3 value to existing object

So, I have this blood drip script where when the blood drip part gets touched, it waits a bit and anchors itself, and disables its collisions. It works like a charm, however, I wanted to add a feature for when it hits an object named “BloodPooled”, it will add size to it by a stud and delete itself.

Here is the code:

script.Parent.Touched:Connect(function(hit)
	
	if hit.Name == "BloodPooled" then
		hit.Size += Vector3.new(1, 0.001, 1)
		
		script.Parent:Destroy()
	else
		script.Parent.Size = Vector3.new(1, 0.001, 1)
	
	wait(1.5)
	
	script.Parent.Anchored = true
	script.Parent.CanCollide = false
	
	script.Parent.Name = "BloodPooled"
		script.Parent.Parent = game.Workspace.BloodPools
	end
end)

Whenever it gets touched again, it just reverts back to the original size of 1, 0.001, 1.

Oh, and yes, I know this is janky and I should be using ray-casts however I’m really bad at ray-casts.

It seems as though whenever a new blood drop hits an existing one, both fire the touch event, removing one, and resizing the other. Instead, try disabling the touch connection if the blood drop is finalized, i.e. not going to fall again.

I think this code fix should work:

local conn

conn = script.Parent.Touched:Connect(function(hit)
	if hit.Name == "BloodPooled" then
		hit.Size += Vector3.new(1, 0.001, 1)
		script.Parent:Destroy()
	else
		conn:Disconnect()
		script.Parent.Size = Vector3.new(1, 0.001, 1)
		wait(1.5)
		script.Parent.Anchored = true
		script.Parent.CanCollide = false
		script.Parent.Name = "BloodPooled"
		script.Parent.Parent = game.Workspace.BloodPools
	end
end)
1 Like