Here below oyu have my code, I think there’s no error, but looks like yes… Basically, when I call module:FindNearesetSpawnSpot it doesn’t prints ‘some1 called’, this is serversided:
server:
Players.PlayerAdded:Connect(function(plr)
local Apartment = ApartmentsModule.NewApartment(plr, 'NewApartment','Institutional White')
Apartment:FindNearesetSpawnSpot()
end)
OOP module:
local module = {}
module.__index = module
module.NewApartment = function(Player, TypeOf, Color)
print('returning')
return setmetatable({Owner=Player,ApartmentName = TypeOf,ApartmentGarageSize = 2,ApartmentWallColor = Color,Model = game.ReplicatedStorage.Apartmentss:FindFirstChild(TypeOf):Clone()}, module)
end
function module:Retry()
self:FindNearesetSpawnSpot()
end
function module:FindNearesetSpawnSpot()
print('some1 called')
local Folder = workspace.Apartments:GetChildren()
if #Folder < 1 then
self:Spawn(Vector3.new(math.random(4000), -10, math.random(4000)))
elseif #Folder > 0 then
local free = false
local randomSpawn = Vector3.new(math.random(4000), -10, math.random(4000))
for i,v in ipairs(workspace.Apartments:GetChildren()) do
local orientation,size = v:GetBoundingBox()
if (orientation^2 - randomSpawn^2) > 100 then
free = true
end
end
print(free)
if free then
self:Spawn(randomSpawn)
print('Spawned.')
elseif free == false then
self:Retry()
print('Retrying.')
end
end
end
function module:SetColor(Color)
self.ApartmentWallColor = Color
for i,v in ipairs(self.Model.Walls:GetChildren()) do
v.BrickColor = BrickColor.new(self.ApartmentWallColor)
end
end
function module:Spawn(Vector)
print('spawning')
self.Model.Parent = workspace.Apartments
self.Model:MoveTo(Vector)
self:SetColor(self.ApartmentWallColor)
end
return module