Im writing a module to handle the client side placement and i will write a script on the server. Im getting this error. attempt to call method 'Place' (a nil value) Module:
local Placer = {}
local runservice = game:GetService("RunService")
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
function Placer:Place(model, base)
self._running = true
self._model = model
self._base = base
end
function Placer:Cancel()
self._running = false
self._model = nil
self._base = nil
self._roundedpos = nil;
end
function round(num,multiple)
if num%multiple==0 then
return num
elseif num%multiple>multiple/2 then
i = 0
repeat i = i+1 until (i*multiple>num)
return i*multiple
elseif num%multiple<((multiple/2)+.5) then
i = 0
repeat i = i+1 until (i*multiple>num)
return ((i*multiple)-multiple)
end
end
function roundVector3(vector3, roundby)
local newvector3 = Vector3.new(round(vector3.x, roundby),round(vector3.y, roundby),round(vector3.z, roundby))
return newvector3
end
function contains(lit, object)
for i,v in pairs(lit) do
if v == object then
return true
end
end
return false
end
function Placer:Update()
if self._running then
local previous = self._roundedpos or roundVector3(Vector3.new(self._base.Position.X, self._base.Position.Y+ (self._model.PrimaryPart.Size.Y / 2) + (self._base.Size.Y / 2), self._base.Position.Z), 2)
local new = roundVector3(mouse.Hit.p)
self._model:SetPrimaryPartCFrame(CFrame.new(new))
if contains(self._model.PrimaryPart:GetTouchingParts(), self._base) then
self._roundedpos = new
else
self._model:SetPrimaryPartCFrame(CFrame.new(previous))
end
end
end
function Placer.new()
local self = setmetatable({_running = false;
_model = nil;
_base = nil;
_roundedpos = nil;
}, Placer)
return self
end
return Placer
then the local:
local runservice = game:GetService("RunService")
local placemodule = require(script.ModuleScript)
local placer = placemodule.new()
placer:Place(workspace.Test, workspace.Base)
runservice.RenderStepped:Connect(function()
placer:Update()
end)
Thank you in advance. Notice: I want to keep it as a module script instead of changing it to a normal localscript.
