Checking if player is inside AOE? (Check part inside part)

Hi, Im trying to make a gear where when executed, the gear would size by 30, 30, 30 and when it finishes sizing up, it checks if theres any characters inside of the AOE and then deletes them. I tried using :GetTouchingParts() but it doesn’t seem to work?

Server script inside of gear


local tweenservice = game:GetService("TweenService")

script.Parent.Activated:Connect(function()
    game:GetService("ReplicatedStorage").woah:FireAllClients(1, script.Parent.Parent)
end)

game:GetService("ReplicatedStorage").haow.OnServerEvent:Connect(function(player, number)
    if number == 1 then
        print("check2")
        script.Parent.AOE.Size = Vector3.new(30,30,30)
        local parts = script.Parent.AOE:GetTouchingParts()
        print("checking parts...")
        for i,v in pairs(parts) do
            print(i)
            print(v)
        end
        print("end")
        end
end)

Local script inside StarterGui


game:GetService("ReplicatedStorage").woah.OnClientEvent:Connect(function(number, user)
    if number == 1 then
        local goal = {}
        goal.Size = Vector3.new(30,30,30)

        local tweeninfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)

        local tween = game:GetService("TweenService"):Create(user["Time Destroy"].AOE, tweeninfo, goal)

        tween:Play()
        tween.Completed:Wait()
        game:GetService("ReplicatedStorage").haow:FireServer(1)
        print("check1")
    end
end)

Does anyone know how to fix it?

Hmm, for me I think instead of using GetTouchingParts() I would just make a connection with Touched and TouchEnded for efficiency.

local AOE = script.Parent.AOE
local CharactersInside = {}

AOE.Touched:Connect(function(object)
	if object.Parent:FindFirstChildOfClass("Humanoid") then
		CharactersInside[object.Parent] = 1
	end
end)

AOE.TouchEnded:Connect(function(object)
	if object.Parent:FindFirstChildOfClass("Humanoid") then
		CharactersInside[object.Parent] = nil
	end
end)

game:GetService("ReplicatedStorage").haow.OnServerEvent:Connect(function(player, number)
	if number == 1 then
		print("check2")
		AOE.Size = Vector3.new(30,30,30)

		print("checking parts...")
		-- object is the character model while _ is the value which is 1
		for object, _ in pairs(CharactersInside) do
			print(object)
		end

		print("end")
	end
end)

You could just use spatial queries, since they are very fast and accomplish the goal your looking for

local AOEPart = script.Parent.AOE --i recommend you to define this at the top of your script to reduce long script.Parent lines

if number == 1 then
        print("check2")
        script.Parent.AOE.Size = Vector3.new(30,30,30)
        local parts = workspace:GetPartBoundsInBox(AOEPart.CFrame, AOEPart.Size) --you should put a blacklist to not return parts that belongs to the tools parent
        print("checking parts...")
        for i,v in pairs(parts) do
            print(i)
            print(v)
        end
        print("end")
end

The api reference:
https://create.roblox.com/docs/reference/engine/classes/WorldRoot#GetPartBoundsInBox

for GetTouchingParts to work you must have a touchintrest inside the part

for this to be done make a connection variable and assign it to aoe.touched:connect(function() end)
dont put anything in the function

then run gettouchingparts do what you need to do then after everything, disconnect your connection with connection:Disconnect()

.Touched and .TouchedEnded are not good choices for something like this since it will only call when a part is moving within that part

you could also use region3 if you want, but gettouchingparts is the easiest