Hi! I’m working on a small game inspired by Grow a Garden, where players can plant seeds. Each seed can be planted by clicking on a designated area called PlantablePart
within the player’s plot. I want to save details like the plant’s position (in wich PlantablePart it was planted), growth status, and other stats so that they can be loaded when the player rejoins the game. What would be the best approach to implement this?
I don’t really have much experience with DataStore, or in general saving data.
Serialization
and Deserialize
is what you need its basically compressing the properties of the Plant
in this case, into a readable / savable form and example would be like
function SerializeInstance(instance)
local data = {
CFrame = instance.CFrame,
Growth = instance:GetAttribute("Growth"),
Name = instance.Name
}
return data
end
function DeserializeInstance(data)
local instance = ReplicatedStorage:FindFirstChild(data.Name):Clone()
instance.CFrame = CFrame.new(unpack(data.CFrame))
instance:SetAttribute("Growth", data.Growth)
instance.Name = data.Name
instance.Parent = workspace.PlayerPlots.UserName
return instance
end
I may not be much help since I never really made something like this but I believe that is the general idea, then just loop the player’s saved plants then call the DeserializeInstance
when they join and when they leave use SerializeInstance
2 Likes