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

Unable to cast value to object? I'm having trouble with region3?

I'm trying to make a placement system, but I keep getting this error when using :FindPartsInRegion3withIgnoreList()

Here's the part of the script I think that is causing the problem:

	local hb = model.HitBox
	local region3 = Region3.new(
		Vector3.new(
			hb.Position.X-2,
			hb.Position.Y-3.5,
			hb.Position.Z-2.5
			),
		Vector3.new(
			hb.Position.X+2,
			hb.Position.Y+3.5,
			hb.Position.Z+2.5
			)
	)
	local partsinRegion = workspace:FindPartsInRegion3WithIgnoreList(region3, model, 100)
	local function p() 
		print(tostring(partsinRegion[1]))
	end
	pcall(p)
	-- just to test to see if it returns an object

2 answers

✓ Accepted answer

Just use FindPartsInRegion3 instead of FindPartsInRegion3WithIgnoreList! FindPartsInRegion3 will ignore whole models, FindPartsInRegion3WithIgnoreList only blocks objects in an array!


#Final Product

local hb = model.HitBox
local region3 = Region3.new(
    Vector3.new(
        hb.Position.X-2,
        hb.Position.Y-3.5,
        hb.Position.Z-2.5
        ),
    Vector3.new(
        hb.Position.X+2,
        hb.Position.Y+3.5,
        hb.Position.Z+2.5
        )
)
local partsinRegion = workspace:FindPartsInRegion3(region3, model, 100)
local function p() 
    print(tostring(partsinRegion[1]))
end
pcall(p)
-- just to test to see if it returns an object

Hope it works!(My shortest answer yet!)

Two problems:

  • withignorelist takes a table of parts, with FindPartsInReigon3() takes a second parameter which is an instance which all its decendants should ignore.

6 comments

0

same ansver as dragon lord but upvote cuz u tried :D

0

PFFF I was first.

0

Wait a minute, I literally said the answer in the community chat, anyone could've copied and pasted that here...

0

I just realised I have no cool down when it comes to making comments and questions

0

Hola!

0

Ty lol

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