I am trying to make a magic spell attack by creating a new Instance and using GetTouchingParts and printing every part from the GetTouchingParts table, but when the spell is activated only the tool will get printed out. I randomly tried to put a Touched event in front of the table as shown bellow and the script worked perfectly, the everything I needed to print out got printed and no lag occurred. Why is this working when I put a touched event in front?
local sphere = Instance.new("Part")
sphere.Parent = workspace
sphere.CFrame = tool.Handle.CFrame
sphere.Size = Vector3.new(7,7,7)
sphere.Anchored = true
sphere.CanColide = false
event:FireClient(plr, "attack"..nr.." is here!")
wait(.1)
sphere.Touched:connect(function() end) --if i remove this line it will print the hhandle -WHY??? IDK!!!!
local table2 = sphere:GetTouchingParts()
for _, hit in pairs(table2) do
if not hit.Parent == character then
print(hit.Name.." "..hit.Parent.Name)
end
end
wait(.75)
shpere:Destroy()
I tested it with the “sphere.Touched” line and without a lot of times. Why is this happening, does the touched event stop the script for some nano-seconds or what?