#Pet Growth System Foundation

1 messages Β· Page 1 of 1 (latest)

tacit bough
#

I've created a prototype for pet growth where currently there are four stages (Egg, baby, teen, adult) and once the pet goes to the next stage the model is supposed to change (currently just a sphere, cube, rectangle and cylinder). My current system is revealing making the model correct collideable and visible while being a child to the an overall model that parents every stage, this is the only thing I could think of being new to Roblox Studios and Lua, is there a better way to do this?

devout onyx
#

@tacit bough

#

local pet = script.Parent
local stages = {
{Name = "Egg", Shape = "Sphere", Size = Vector3.new(1,1,1)},
{Name = "Baby", Shape = "Cube", Size = Vector3.new(1.5,1.5,1.5)},
{Name = "Teen", Shape = "Block", Size = Vector3.new(2,3,2)},
{Name = "Adult", Shape = "Cylinder", Size = Vector3.new(2,4,2)}
}

local function changeStage(stageIndex)
local stageData = stages[stageIndex]

-- Clear previous shape
for _, child in ipairs(pet:GetChildren()) do
    if child:IsA("BasePart") then
        child:Destroy()
    end
end

-- Create new part
local part = Instance.new("Part")
part.Name = stageData.Name
part.Shape = Enum.PartType[stageData.Shape]
part.Size = stageData.Size
part.Anchored = false
part.CanCollide = true
part.Parent = pet

-- Position at center (adjust as needed)
part.Position = pet:GetPivot().Position

end

-- Example usage:
changeStage(1) -- Egg stage

#

this work for you?

tacit bough
#

I'm sorry for my request being unclear, that works for what I asked but the vision is for the objects to be models in the future for the actual pets unless it's possible to use this system on an imported model.

wooden badgeBOT
#

studio** You are now Level 1! **studio

devout onyx
#

local PetManager = {}

PetManager.Stages = {
{
Name = "Egg",
Model = game.ServerStorage.PetModels.Egg
},
{
Name = "Baby",
Model = game.ServerStorage.PetModels.Baby
},
{
Name = "Teen",
Model = game.ServerStorage.PetModels.Teen
},
{
Name = "Adult",
Model = game.ServerStorage.PetModels.Adult
}
}

function PetManager.SetStage(petContainer, stageIndex)
local stageData = PetManager.Stages[stageIndex]
if not stageData then return end

for _, child in ipairs(petContainer:GetChildren()) do
    if child:IsA("Model") or child:IsA("BasePart") then
        child:Destroy()
    end
end

local newModel = stageData.Model:Clone()
newModel:PivotTo(petContainer:GetPivot())
newModel.Parent = petContainer
newModel.Name = stageData.Name

if newModel.PrimaryPart == nil then
    local largestPart
    for _, part in ipairs(newModel:GetDescendants()) do
        if part:IsA("BasePart") then
            if not largestPart or part.Size.Magnitude > largestPart.Size.Magnitude then
                largestPart = part
            end
        end
    end
    if largestPart then
        newModel.PrimaryPart = largestPart
    end
end

end

return PetManager

#

this work?

#

@tacit bough

tacit bough
#

Don't know much about scripting but this seemingly looks like what I'm after

#

If I were to have an array of pets I would just for example have the stage model names as "FireEgg" "ForestEgg" (assuming "fire" and "forest" are pet names)?

tacit bough
#

@devout onyx

devout onyx
#

ServerStorage
└── PetModels
β”œβ”€β”€ FireEgg
β”œβ”€β”€ FireBaby
β”œβ”€β”€ FireTeen
β”œβ”€β”€ FireAdult
β”œβ”€β”€ ForestEgg
β”œβ”€β”€ ForestBaby
β”œβ”€β”€ ForestTeen
└── ForestAdult

#

set this up

#

local PetManager = {}

function PetManager.SetStage(petContainer, petType, stageName)
local modelName = petType .. stageName
local stageModel = game.ServerStorage.PetModels:FindFirstChild(modelName)
if not stageModel then return end

for _, child in ipairs(petContainer:GetChildren()) do
    if child:IsA("Model") or child:IsA("BasePart") then
        child:Destroy()
    end
end

local newModel = stageModel:Clone()
newModel:PivotTo(petContainer:GetPivot())
newModel.Parent = petContainer
newModel.Name = modelName

if not newModel.PrimaryPart then
    local largestPart
    for _, part in ipairs(newModel:GetDescendants()) do
        if part:IsA("BasePart") then
            if not largestPart or part.Size.Magnitude > largestPart.Size.Magnitude then
                largestPart = part
            end
        end
    end
    if largestPart then newModel.PrimaryPart = largestPart end
end

end

return PetManager

tacit bough
#

Ahhhh okay would putting them in files under server storage like "fire stages" for orginizaional purposes break anything?

devout onyx
#

i mean

wooden badgeBOT
#

studio** You are now Level 4! **studio

devout onyx
#

no

#

but if u perfer that\

#

ServerStorage
└── PetTypes
β”œβ”€β”€ Fire
β”‚ β”œβ”€β”€ Stages
β”‚ β”‚ β”œβ”€β”€ Egg
β”‚ β”‚ β”œβ”€β”€ Baby
β”‚ β”‚ β”œβ”€β”€ Teen
β”‚ β”‚ └── Adult
└── Forest
β”œβ”€β”€ Stages
β”‚ β”œβ”€β”€ Egg
β”‚ β”œβ”€β”€ Baby
β”‚ β”œβ”€β”€ Teen
β”‚ └── Adult

#

thjen thius

#

local PetManager = {}

function PetManager.SetStage(petContainer, petType, stageName)
local stagePath = ("PetTypes/%s/Stages/%s"):format(petType, stageName)
local stageModel = game.ServerStorage:FindFirstChild(stagePath, true)
if not stageModel then return end

for _, child in ipairs(petContainer:GetChildren()) do
    if child:IsA("Model") or child:IsA("BasePart") then
        child:Destroy()
    end
end

local newModel = stageModel:Clone()
newModel:PivotTo(petContainer:GetPivot())
newModel.Parent = petContainer
newModel.Name = petType..stageName

if not newModel.PrimaryPart then
    local largestPart
    for _, part in ipairs(newModel:GetDescendants()) do
        if part:IsA("BasePart") then
            if not largestPart or part.Size.Magnitude > largestPart.Size.Magnitude then
                largestPart = part
            end
        end
    end
    if largestPart then newModel.PrimaryPart = largestPart end
end

end

return PetManager

tacit bough
#

Thank you so much my friend you're a life saver