Hi, thanks for taking your time to read this. I am having trouble with figuring out how to solve this error. Basically, I setup an IgnoreList at the SetupLists function and basically here:

local Object = workspace:FindPartOnRayWithIgnoreList(CreateRay, self.ignoreList)

is where the error is. It says Unable to cast value to Object. I have no idea how to figure out how to fix, I tried adding the if BasePart statement but that did nothing, if anyone can help that'd be really great. Thank you.

local Players = game:GetService("Players")

local Scp106 = {}
Scp106.__index = Scp106

function Scp106.new()
	local self = {}
	setmetatable(self, Scp106)
	
	-- MAKE SURE TO RESET TABLES BELOW IN CORE STARTING SCRIPT.
	self.ignoreList = {}
	self.connections = {}
	
	-- MOVE TO CORE SCRIPT LATER.
	self:SetupLists()
	wait(2)
	self:FindConnections()
end

function Scp106:SetupLists()
	for _, Object in pairs(workspace:GetDescendants()) do
		if not Object.Name:match("Floor") then
			if Object:IsA("BasePart") then
				print(Object:GetFullName())
				table.insert(self.ignoreList, Object:GetFullName())
			end
		else
			table.insert(self.connections, Object:GetFullName())
			self.connections[Object:GetFullName()] = 0;
		end
	end
end

function Scp106:FindConnections()
	for _, Player in pairs(Players:GetChildren()) do
		local Character = workspace:FindFirstChild(Player.Name)
		if Character then
			local Humanoid = Character:FindFirstChild("Humanoid")
			local RootPart = Character:FindFirstChild("HumanoidRootPart")
			
			if (Humanoid and RootPart) then
				local CreateRay = Ray.new(Character.PrimaryPart.CFrame.p, Vector3.new(0, -1000, 0))
				local Object = workspace:FindPartOnRayWithIgnoreList(CreateRay, self.ignoreList)
				if Object.Name:match("Floor") then
					self.connections[Object:GetFullName()] = self.connections[Object:GetFullName()] + 1;
				end
			end
		end
	end
	
	for i,v in pairs(self.connections) do
		print(v)
	end
end

return Scp106

3 comments

0

I feel lile somthinhs worung with line 22 or 21

0

Ill check it out.

0

There probably is with the error but idk how to fix that.