Touch not registering?

Another day another stupid scripting issue that shouldn’t be an issue in the first place

As the title says, the touch in this script is simply not registering

print("Start")
script.Parent.Touched:Connect(function(hit)
print("touched")
if hit.Parent:FindFirstChild("Humanoid") then
	print("killed")
		hit.Parent.Humanoid.Health = 0
	end
	if hit:IsA("BasePart") then
		if hit.Parent.Name == "Shelter" or hit.Parent:FindFirstChild("Type") then
			print("Sheltered")
			return
				else
			print("else")
			local random = math.random(1,3)
			if random == 2 then
				print("destruction")
				local math = script.Parent.Position - Vector3.new(-15,0,0)
				hit.Position = hit.Position -  math
				hit.Anchored = false
				task.wait(2)
				hit:Destroy()
				print("Bye Bye!")
			end
			end
		end
end)
print("Finish")


When this blue part moves towards these parts, the touch function just does not register
However, when I drop the part from above I guess it registers?
Could it be the movement that’s the problem and if so how would I fix it

Could you show a video of it in action?

robloxapp-20231227-1605573.wmv (99.1 KB)
(I don’t have a recording software on this computer so I had to use Roblox Studio’s recording)
For some reason the output didn’t record but when I checked the output it didn’t print “touched”

Touched only fires on contact during physical movement. It appears you are changing CFrames (manually or with a TweenService), so it doesn’t fire, the parts simply overlap. Meaning, the detecting part must be unanchored and simulated.

I’d use GetPartBoundsInBox() if I were you, especially if you are working on something like a wave or tsunami going towards players.

Your code could look somewhat like this:

tween:Play()

while tween.PlaybackState == Enum.PlaybackState.Playing do
	local parts = workspace:GetPartBoundsInBox(...)
	task.wait()
end
1 Like

Thank you, I’ll also now keep that in mind when making any scripts that require touch!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.