camera:ScreenPointToRay() returns nil in Team Create

I’m working on a plugin that functions similar to Alt+Click except you can continue to select parts past the initially selected part. For some reason camera:ScreenPointToRay() always returns nil in Team Create while local place files work fine with this plugin.

local Selection = game:GetService("Selection")
local UIS = game:GetService("UserInputService")
local camera = workspace.CurrentCamera
local lastSelection
local filterList = {}
local raycastParams 


local function RefreshFilter()
	raycastParams = RaycastParams.new()
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	raycastParams.FilterDescendantsInstances = filterList
	raycastParams.IgnoreWater = true
end
RefreshFilter()

local function FindSelection(inputObject)
	local unitRay = camera:ScreenPointToRay(inputObject.Position.X, inputObject.Position.Y)
	local result = workspace:Raycast(unitRay.Origin, unitRay.Direction * 1000, raycastParams)
	if result and result.Instance then
		Selection:Set({result.Instance})
		table.insert(filterList, result.Instance)
		RefreshFilter()
	else
		filterList = {}
		RefreshFilter()
	end
end

UIS.InputBegan:Connect(function(inputObject,gameProcessed)
	if not gameProcessed and inputObject.UserInputType == Enum.UserInputType.MouseButton1 and (UIS:IsKeyDown(Enum.KeyCode.X)) then  
		FindSelection(inputObject)
	end
end)

UIS.InputEnded:Connect(function(inputObject,gameProcessed)	
	if inputObject.UserInputType == Enum.UserInputType.Keyboard and (inputObject.KeyCode == Enum.KeyCode.X) then
		filterList = {}
		RefreshFilter()
	end
end)
1 Like

Couldn’t you just use mouse.Target for this?

Edit: Mouse.Target doesn’t give you the model, but gives the part

Theres a plugin mouse as well

mouse.TargetFilter only allows one object at a time to be filtered. I need to filter multiple objects at once.

1 Like

Here’s a good thread that may help

Basically what they are saying that the current camera isn’t guaranteed to be the same. I can probably guess that this is because other people.

Edit: They explain the same issues between a real place and local place.

Isnt Workspace:Raycast() supposed to have another argument in between the brackets?