What do you want to achieve? Basically, I just started learning OOP and trying Advanced Module Scripts, I’m trying to make this Animal Model change positions to their expected positions, however this does not work for some reason.
local testModule = require(script.Parent.TestModule)
local currentAnimal = nil
amongus = testModule.new("Lion", 100, 3)
spawnAnimal = testModule:spawn(game.ReplicatedStorage.Lion, workspace.SpawnPart.Position)
print(amongus)
for i, v in pairs(amongus) do
print(i .. ": " .. v)
end
for index, value in pairs(spawnAnimal) do
if index == "Animal" then
value:Clone().Parent = workspace.Animals
currentAnimal = value
end
if index == "AnimalPosition" and currentAnimal then
print(value)
currentAnimal.Torso.Position = Vector3.new(value)
end
end
Module:
local Animals = {}
Animals.__index = Animals
print("Loaded AnimalService")
--[[local module = {
food = "chicken wing",
otherFood = "hotdog",
changeFood = function(self, expected)
self.food = expected
print("Now ".. expected)
end
}]]--
function Animals.new(animalName, animalHealth, animalSize)
local newAnimal = {}
setmetatable(newAnimal, Animals)
newAnimal.Name = animalName
newAnimal.Health = animalHealth
newAnimal.Size = animalSize
return newAnimal
end
function Animals:spawn(animalObject, position)
local expectedToSpawn = {}
setmetatable(expectedToSpawn, Animals)
expectedToSpawn.AnimalPosition = position
expectedToSpawn.Animal = animalObject
return expectedToSpawn
end
--print("Was ".. module.food)
return Animals
The TestModule is the Module you see on the second script, if I do Animals:spawn(animalObject, position) it will return the animalObject we want to spawn and the expected position of the animal (where we want to place the animal)
There’s the possibility that the PrimaryPart of the Model was not set – when creating the Animals, ensure that Model.PrimaryPart is not nil.
Otherwise, referring to the original post, are any of the parts being teleported to the new location or is nothing happening at all? Any errors in the Output when you try to adjust its position?
I’d suggest adding print statements inside of the functions and various conditional statements (if you haven’t already) to determine which conditions are being met in addition to different values depending on what happens (e.g. if the condition where the Animal is about to be teleported was met, try printing its Position before & after trying to change it to a new value).