Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does it say unable to cast value to object?

Here is my script:

local region = Region3.new(Vector3.new(script.Parent.Reg1.Position), Vector3.new(script.Parent.Reg2.Position))

while true do
	wait()
	local touching = game.Workspace:FindPartsInRegion3(region, 1000)
	for i,v in pairs(touching) do
		if v.Parent:FindFirstChild('Humanoid') and v.Parent:FindFirstChild("HInfect") then
			local number = math.random(1,10)
			if number == 1 then
				v.Parent.HInfect:Destroy()
			else
				v.Parent.Humanoid:TakeDamage(v.Parent.Humanoid.Health)
			end
		end
	end
end

1 answer

✓ Accepted answer

Because the 2nd parameter is a model or part the function will ignore, but you passed a number I'm assuming you want this to be the maxParts parameter.

If you're not gonna ignore any parts, set the parameter to nil:

local touching = workspace:FindPartsInRegion3(region, nil, 1000)

1 comment

0

Thanks. Also for some reason it only gets the baseplate. Did I format the region3 wrong in the first line?

This discussion is preserved as it was. New answers, comments, and votes are closed.