.Touched event randomly stops working after 1-2 minutes

Exactly what it sounds like.
I’m positioning a cylinder to the players feet:

local Range = game.ReplicatedStorage.Range:Clone()
local char = game.Players.LocalPlayer.Character
Range.Parent = char
while task.wait() do
	local position = char:WaitForChild("HumanoidRootPart").Position - Vector3.new(0, 3.3, 0)
	Range.Position = position
end

And using .Touched to know if 2 parts are touching:

part.Touched:Connect(function(hit)
	print("Touched with: "..hit) --after 1-2 minutes "Range" isn't printed anymore
	if hit.Name == "Range" then
		-- do stuff
	end
end)

Even though the 2 parts are clearly touching:
image

Both scripts are LocalScripts and are located inside ReplicatedFirst.

2 Likes

Why not check the touched event for just Range (if that’s not what you’re already doing). As for your original problem I have no idea why it would stop after a couple minutes.

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Range = game.ReplicatedStorage.Range:Clone()
Range.Parent = Character

Range.Touched:Connect(function(Hit)
	if Hit:IsDescendantOf(Character) then return end -- If you dont want Range to touch your character
	
	print("Touching: ".. Hit.Name)
	if Hit.Name == "blah blah" then
		-- do stuff for the touching part
	end
end)

while task.wait() do
	local Position = Character:WaitForChild("HumanoidRootPart").Position - Vector3.new(0, 3.3, 0)
	Range.Position = Position
end
1 Like

Hi! Sorry if I am wrong but I am guessing its just timing out from overload from doing the same task repeatedly, Might I recommend doing zones instead of touched events

Zone Service I think will solve your problem here since its avoiding using any classic touched method

2 Likes

Thank you, that fixed the problem. However another one came with it and I’ll have to make a new topic about it.

Also @My47thChromosome thank you for taking your time and trying to help!

1 Like

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