Unable to cast value to object error

I’m trying to make a touched event that detects if an object that the fireball touched is part of the map, but right now I’m getting an error that says “Unable to cast value to Object”

hit:IsDescendantOf(workspace.Maps:GetChildren())

Are there multiple maps at once in the game?

Not yet, there’s only one map which consists of a block

Then you should replace this with the path to the map and remove :GetChildren() .

I can see this working, but right now I want it to be able to detect all the parts in every map under the Maps folder

I see, then you could make a for loop for this. Example:

local fireball = --Path to fireball

fireball.Touched:Connect(function(hit)
	for i,v in pairs(workspace.Maps:GetChildren()) do
		if hit:IsDescendantOf(v) then
			--Code
		end
	end
end)

Thanks, but how should I combine it with this code that makes the fireball detect for humanoids? Right now I’m getting a red underline error at the word ‘for.’

newFireball.Touched:Connect(function(hit)
		if hit.Parent.Name ~= player.Name and hit.Parent:FindFirstChild("Humanoid") 
			or for i,v in pairs(workspace.Maps:GetChildren()) do
				if hit:IsDescendantOf(v) then
newFireball.Touched:Connect(function(hit)
	if hit.Parent.Name ~= player.Name then
		if hit.Parent:FindFirstChild("Humanoid") then
			--Code
		else
			for i,v in pairs(workspace.Maps:GetChildren()) do
				if hit:IsDescendantOf(v) then
					--Code
				end
			end
		end
	end
end)

I guess you could do this. If you are doing the same code for both of them I recommend putting that code into a function and calling it in the “–Code” part.

IsDescendantOf takes a single Instance. By using GetChildren you are providing it with a table.
Simply check if hit IsDescendantOf Maps or use a loop to check if it IsDescendantOf each individual map.

Hi, if you would mind me adding a new reply, right now the fireball would hit everything in the workspace including parts that are not part of the ‘Maps’ folder. I just want the fireball to hit parts that are inside the folder, do you know what I should change? Fyi: In the workspace, I have a ‘Maps’ folder, and inside it I would add my maps. I currently have a folder called ‘DefaultMap’ folder in it, and inside the ‘DefaultMap’ folder, I have the part that I want the fireball to hit.