Growing anchored part not firing the touched event

I am making a game with a circle on the ground. Whenever the circle touches a part, it should fire the touched event and make the parts collision group change. The circle is anchored and grows to be able to “eat” parts. How can i make the touched event fire?

1 Like

How are these working? Are they initiated through Scripts and not LocalScripts?

1 Like

They work just fine, but i have to drop the part into the circle just for the parts to be eaten. They are made in server scripts

1 Like

Ok, you can use collection service for that:

Spawning Script:

local part = Instance.new("Part", workspace) -- Workspace is the parent
part.CFrame = cframe
part.Name = "ClonedPart"
part.Size = Vector3.new(1,1,1)
part.Anchored = true
part:AddTag("eatParts") -- You can change the tag, just the instance

Then the server code using the collection service

local collectionService = game:GetService("CollectionService")
local tag = "eatParts" -- you can change the tag here as a quick instance
for _, part: BasePart in ipairs(collectionService:GetTagged(tag)) do
	part.Touched:Connect(function(hit)
       local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
       if player then
         print(player.Name.." touched "..part.Name)
       end
   end)
end

Please keep in mind, I did this all on my laptop, so I did this all off of memory, so somethings might print out an error, but they should be easy to fix, if you don’t understand an error that happens please reply to it, and I will try my best. Also the create script was only a reference, just make sure to do the :AddTag() thing to specify what it is!

Also using the CollectionService is better than looping through the whole of the workspace, and is more organized. I hope this helps!

1 Like

That helps with the actual “eating”, but i don’t know how to make the circle fire the touched event. The parts that it is eating are stationary and unanchored. The circle itself stays in the same place, but it grows to eat parts.

1 Like

so are you trying to create a hole.io kind of game? If so you can use GetTouchingParts here is a devlog on how you can use it: Devlog

1 Like

I am going for a hole.io meets cookie clicker type game. I will learn more and try it out. Thanks!

1 Like

I can’t get it to work, but I will try again tomorrow. Thank you for your help!

1 Like

I think one of the two parts related to the touched event must be unanchored in order for the event to fire. Also you may want to ensure BasePart.CanTouch is true for both parts.

An alternative to the above is manually checking for overlap by calling functions like workspace:GetPartsInPart(basePart) and basePart:GetTouchingParts() every time you resize the part.

1 Like

Update: I tried to use GetTouchingParts, but it wasn’t working. I looked it up, and i found GetPartsBoundsInBox, which worked perfectly. Thank you for all your help!

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