I’m trying to make something which requires me to used a touched event and it works fine. The problem is it doesn’t seem to notice when anything cloned touches it.
Here’s the code for it:
script.Parent.Touched:Connect(function(hit)
print(hit)
end)
It prints handle when a tool touches it but when I clone it it doesn’t notice the clone or its children.
The invisible part is a child of the clone.
It prints “Handle” when the object I’m holding touches it. The Code that clones the object happens on the server.
Why is this happening?
So if I’m reading this correctly you’re wondering why the cloned pencil isn’t making the invisible part fire a .Touched signal after it’s cloned into the invisible part right?
I’m assuming that the cloned pencil is anchored and set to a position within the invisible part, if so then the reason for the touched signal to not be fired is simple. Touched only fires as a result of physics movement, which cloning and setting the pencil’s position is not.
If you would like to detect the pencil inside of the invisible part I recommend using Runservice.HeartBeat, together with BasePart:GetTouchingParts(). Your script would then look something like this:
local Runservice = game:GetService("RunService")
local InvisibleParts = workspace.InvisiblePart
Runservice.Heartbeat:Connect(function()
local TouchingParts = InvisibleParts:GetTouchingParts() --Returns a table with the touching parts
print(TouchingParts)
end)
Read more on the pages linked below.
https://create.roblox.com/docs/reference/engine/classes/BasePart#Touched
https://create.roblox.com/docs/reference/engine/classes/BasePart#GetTouchingParts