Script doesnt detect if being touched by part but does detect if touched by rig?

what i want this script to do is detect if it hits a part. and if it does it will check if its a player. and if it isnt it will create a hitbox and destroy the fireball (havent scripted that part yet) but it only works if it hits a rig. if it hits a part not apart of a rig it doesnt detect as touched

local plrs = game:GetService('Players')
local debounce = false

script.Parent.Touched:Connect(function(hit)
	if debounce then return end
	if plrs:GetPlayerFromCharacter(hit.Parent) then return end
	if plrs:GetPlayerFromCharacter(hit.Parent.Parent) then return end
	debounce = true
	local hitbox = Instance.new('Part')
	hitbox.Name = 'FireballHitbox'
	script.Parent:Destroy()
end)

The function doesn’t work when it tries to hit a non-player part, because of these two lines:

	if plrs:GetPlayerFromCharacter(hit.Parent) then return end
	if plrs:GetPlayerFromCharacter(hit.Parent.Parent) then return end

If you remove those two lines, any part that touches the fireball will make the code run.

i tried removing them but the same thing happens + it runs when it hits a player now

In case you want to detect if a part is a descendant of a character, you may want to use this piece of code:

    local currentParent = hit
    local humanoid

    repeat
        humanoid = currentParent:FindFirstChild("Humanoid")
        currentParent = currentParent.Parent
    until currentParent == workspace or humanoid

    if humanoid then
        -- There's a humanoid found, run code here when it's about a character/player character
        -- humanoid.Parent will be the character found
    else
        -- Non-humanoid part
    end

this does detect humanoids but for some reason doesnt for non humanoid parts (i also checked all the parts and they have CanTouch enabled)

Make sure that your original part + your target parts have CanQuery and CanTouch enabled too, are they enabled?

i believe the target parts have canQuery enabled but ill check the fireball

i enabled both canQuery and canTouch on both the fireball and otherparts but still nothing

Try putting a print(“HIT”) at the first line of the connection to check if at least it detects the part

i tried this and it doesnt print when not hitting something with a humanoid

Then there’s nothing wrong with the code, you should check carefully groupcollisions in case you changed anything about it, and also try to enable cancollide temporally to test it

this is just a random idea but could this be the problem (this is what moves the fireball)

local offset = CFrame.new(0,0,-3)

while true do
	script.Parent.CFrame = script.Parent.CFrame:ToWorldSpace(offset)
	task.wait(0.025)
end

You are moving the fireball 3 units every 0.025 frames.
Parts that are between those 3 units may not get detected as what the moving does is that it INSTANTLY moves the part

Thin walls may not get detected, you may consider using something like raycasting/shapecasting

Another alternative would be the raycasthitbox module, really useful module that can be used for melee or other miscellaneous items such as projectiles.

i tried with this module. i made the part move only one stud every 0.005 or so seconds. i made sure to add the dmg points and set the detection mode to part mode but it still doesnt detect anything. (cantouch and canquery is enabled on everything and there are no other collision groups made)

local offset = CFrame.new(0,0,-1)

local RaycastHitbox = require(game:GetService('ReplicatedStorage').RaycastHitboxV4)

local Hitbox = RaycastHitbox.new(script.Parent)

Hitbox.DetectionMode = RaycastHitbox.DetectionMode.PartMode
Hitbox.Visualizer = true

Hitbox.OnHit:Connect(function(hit, humanoid)
print(hit.Name)
	if humanoid then
		print('hum')
	else
		print('nonhum')
	end
end)

while true do
	script.Parent.CFrame = script.Parent.CFrame:ToWorldSpace(offset)
	task.wait(0.005)
	
end

You have to call Hitbox:HitStart() once for it to indefinitively cast rays. Whenever you want to stop casting rays with the module, call Hitbox:HitStop()

ohhhh i see, it works now. thank you for this i think i might use this more often