Module not updating RootPart's position

I am trying to make a module that updates a parts position based on where a raycast hit.
I have not found any errors so far.

Code:

function Module.Clicked(Player, RootPart)
	local MousePos = userInput:GetMouseLocation()
	local MouseRay = cam:ViewportPointToRay(MousePos.X, MousePos.Y)
	MouseRay = Ray.new(MouseRay.Origin, MouseRay.Direction * 1000)
	local Target,Hit,HitPos = workspace:FindPartOnRay(MouseRay)
	RootPart.Position = HitPos
end

function Module.HoverUpdated(Player, RootPart)
	local MousePos = userInput:GetMouseLocation()
	local MouseRay = cam:ViewportPointToRay(MousePos.X, MousePos.Y)
	MouseRay = Ray.new(MouseRay.Origin, MouseRay.Direction * 1000)
	local Target,Hit,HitPos = workspace:FindPartOnRay(MouseRay)
	RootPart.Position = HitPos
	print(HitPos)
end

How are you triggering the module functions?

1 Like

Through a LocalScript. Here is an example:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Components = game.ReplicatedStorage:WaitForChild(" ")
local RunService = game:GetService("RunService")
local Module = require(game:GetService("ReplicatedStorage"):WaitForChild("MouseRayRoot"))
Mouse.Button1Down:Connect(function()
	Module.Clicked(Player, _G.CurrentPart)
end)
RunService.RenderStepped:Connect(function()
	if _G.CurrentPart == nil then _G.CurrentPart = Components.ExPart:Clone() end
	_G.CurrentPart.Parent = workspace
	Module.HoverUpdated(Player, _G.CurrentPart.RootPart)
end)

Have you tried debugging with prints or breakpoints.

Yes, I have tried prints. Sorry about the delay, I had an appointment.