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?
#Pet Growth System Foundation
1 messages Β· Page 1 of 1 (latest)
@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?
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.
** You are now Level 1! **
ah
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
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)?
@devout onyx
my bad
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
Ahhhh okay would putting them in files under server storage like "fire stages" for orginizaional purposes break anything?
i mean
** You are now Level 4! **
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
Thank you so much my friend you're a life saver