Script not working as intended

In the workspace, I have a ‘Maps’ folder, and inside it are the maps. I currently have a folder called ‘DefaultMap’ in it, and inside that folder, I have the part that I want the fireball to hit. The script that I’m currently using to make the fireball detect for the map parts literally does the opposite. Instead of hitting parts that are in the maps, they hit parts that are outside of the maps and phase through parts that are in the map.

			for a, b in pairs(workspace.Maps:GetChildren()) do
				for c, d in pairs(b:GetChildren()) do
					if hit == d then

Here’s the whole hit detection script:

newFireball.Touched:Connect(function(hit)
		if hit.Parent.Name ~= player.Name and hit.Parent:FindFirstChild("Humanoid") then
			hit.Parent.Humanoid:TakeDamage(dmg)

			newFireball:Destroy()
			local newExplosion = Explosion:Clone()

			newExplosion.CFrame = newFireball.CFrame * CFrame.new(Vector3.new(0,0,-5))
			newExplosion.Parent = game.Workspace
			newExplosion.Sound:Play()

			local ExplosionAnim = TweenInfo.new(
				0.4,
				Enum.EasingStyle.Linear,
				Enum.EasingDirection.Out,
				0,
				false,
				0
			)

			local size = {Size = Vector3.new(25, 25, 25)}
			local tween = TweenService:Create(newExplosion, ExplosionAnim, {Transparency = 1})
			local tween2 = TweenService:Create(newExplosion, ExplosionAnim, size)
			tween:Play()
			tween2:Play()

			local stuntag = Instance.new("ObjectValue")
			stuntag.Name = "StunEffect"
			stuntag.Parent = hit.Parent.Humanoid
			game.Debris:AddItem(stuntag,StunDuration)

			local burntag = Instance.new("ObjectValue")
			burntag.Name = "BurnEffect"
			burntag.Parent = hit.Parent.Humanoid
			game.Debris:AddItem(burntag,burnlength)

			local Tagged = Instance.new("ObjectValue")
			Tagged.Name = "killer"
			Tagged.Value = player
			Tagged.Parent = hit.Parent.Humanoid
			game.Debris:AddItem(Tagged,1)

			game.Debris:AddItem(newExplosion, 1)

			for a, b in pairs(workspace.Maps:GetChildren()) do
				for c, d in pairs(b:GetChildren()) do
					if hit == d then

						newFireball:Destroy()

						newExplosion.CFrame = newFireball.CFrame * CFrame.new(Vector3.new(0,0,-5))
						newExplosion.Parent = game.Workspace
						newExplosion.Sound:Play()

						tween:Play()
						tween2:Play()

						game.Debris:AddItem(newExplosion, 1)
					end
				end
			end

please give more information about the script, you only gave a for a, b loop

The script contains the whole hit detection for maps for the fireball.

Like @FurukanDev stated we need more code, but I already am noticing that you shouldn’t use :GetChildren(), you should instead use :GetDescendants() (However this won’t fix your problem, please give more code)

please send us the script, we cant help you with these informations.

as @noahrepublic said, you must use GetDescendants() , i am still controlling the script maybe there is some another errors.

The script still seems to have to same issue

can you put print(d)
just after if hit == d

Yes, I tried it before except above the hit == d, and it printed a part that is in the Map

so what is the problem ? i dont think i understand correctly.

It hits parts that are outside of the map instead of ones that are in the map

but you said that it printed a part which is inside the map

I meant that even though it printed a part that is inside the map, the fireball still only hits for parts that are outside of the map

can you send a video ?
the output must be in the video too

There aren’t really any output errors, but even if I send a video, it would contain the same problem I mentioned

can you send it i need it to help

I am sorry to say it but without showing us more of the script we can’t help you.

I have updated my post to show the full script for the fireball hit detection, if I post any more code it would be meaningless

did u control the main topic ? he edited it.

I managed to fix the problem, it turns out that the fireball was only detecting for humanoids. I decided to put the map parts detection in front of the humanoid detection and it pretty much worked.

	newFireball.Touched:Connect(function(hit)
		
		for a, b in ipairs(workspace.Maps:GetChildren()) do
			for c, d in ipairs(b:GetChildren()) do
				if hit == d then
					
					newFireball:Destroy()
					local newExplosion = Explosion:Clone()
					newExplosion.CFrame = newFireball.CFrame * CFrame.new(Vector3.new(0,0,-5))
					newExplosion.Parent = game.Workspace
					newExplosion.Sound:Play()
					
					local ExplosionAnim = TweenInfo.new(
						0.4,
						Enum.EasingStyle.Linear,
						Enum.EasingDirection.Out,
						0,
						false,
						0
					)

					local size = {Size = Vector3.new(25, 25, 25)}
					local tween = TweenService:Create(newExplosion, ExplosionAnim, {Transparency = 1})
					local tween2 = TweenService:Create(newExplosion, ExplosionAnim, size)
					tween:Play()
					tween2:Play()

					game.Debris:AddItem(newExplosion, 1)
					
				end
			end
		end
		
		if hit.Parent.Name ~= player.Name and hit.Parent:FindFirstChild("Humanoid") then
			hit.Parent.Humanoid:TakeDamage(dmg)

			newFireball:Destroy()
			local newExplosion = Explosion:Clone()

			newExplosion.CFrame = newFireball.CFrame * CFrame.new(Vector3.new(0,0,-5))
			newExplosion.Parent = game.Workspace
			newExplosion.Sound:Play()

			local ExplosionAnim = TweenInfo.new(
				0.4,
				Enum.EasingStyle.Linear,
				Enum.EasingDirection.Out,
				0,
				false,
				0
			)

			local size = {Size = Vector3.new(25, 25, 25)}
			local tween = TweenService:Create(newExplosion, ExplosionAnim, {Transparency = 1})
			local tween2 = TweenService:Create(newExplosion, ExplosionAnim, size)
			tween:Play()
			tween2:Play()
			
			game.Debris:AddItem(newExplosion, 1)

			local stuntag = Instance.new("ObjectValue")
			stuntag.Name = "StunEffect"
			stuntag.Parent = hit.Parent.Humanoid
			game.Debris:AddItem(stuntag,StunDuration)

			local burntag = Instance.new("ObjectValue")
			burntag.Name = "BurnEffect"
			burntag.Parent = hit.Parent.Humanoid
			game.Debris:AddItem(burntag,burnlength)

			local Tagged = Instance.new("ObjectValue")
			Tagged.Name = "killer"
			Tagged.Value = player
			Tagged.Parent = hit.Parent.Humanoid
			game.Debris:AddItem(Tagged,1)

		end
	end)
end)