So, I’m attempting to program a script that just creates a raycast between your mouse’s hit and your HumanoidRootPart and I keep getting the “This Mouse is no longer active” error message.
Is there anyway to fix this without RemoteEvents?
local EndPoint = script.Parent:WaitForChild("End")
local Tool = script.Parent.Parent
local current_mouse
local last_recorded_correct = Vector3.new(0,0,0)
local function GetCannotInteract()
local cannot_interact = {}
for _, child in pairs(game:GetDescendants()) do
if child:IsA("BasePart") then
if child.CanCollide == false or child.CanTouch == false then
table.insert(cannot_interact, child)
end
end
end
if cannot_interact ~= nil then
return cannot_interact
else
local t1 = {}
return t1
end
end
Tool.Equipped:Connect(function(mouse)
current_mouse = mouse -- Issue comes from here I believe.
end)
Tool.Activated:Connect(function(not_allowed)
not_allowed = GetCannotInteract()
local hit = current_mouse.Hit
local direction = (RaycastAttachment.WorldCFrame.Position - hit.Position) * -1
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = not_allowed
local ray = workspace:Raycast(RaycastAttachment.WorldCFrame.Position, direction, params)
if ray ~= nil then
print(ray)
EndPoint.WorldCFrame = CFrame.new(ray.Position)
last_recorded_correct = ray.Position
else
print("Ray returned as nil.")
EndPoint.WorldCFrame = CFrame.new(last_recorded_correct)
end
end)
Additionally, I have tried Players:GetPlayerFromCharacter()
to get the mouse, but that also failed.