Help With DataStores

Hello Forum! I’ve been working on an emote system for my game and I’ve been stuck on scripting the data saving. (I have a folder inside the player whenever they join thats called emotes and I want to save all the ones that are there and have them come back after the player rejoins.) I want to make it this way so that I can easily add an animation into the emotes folder and then have them leave and rejoin with it. I’m unsure on how to start with this since I have never messed with data saving outside of saving leaderstats

this is my script so far (its not much, I know)

local Viewport = script.Parent.Holder.EmoteDisplay
local dummy = Viewport.World.Rig

local player = game.Players.LocalPlayer
local Emotes = Instance.new("Folder", player)
Emotes.Name = "Emotes"


-- This will play later, I have a animation that will switch ids to make them emote.
local anim = dummy.Humanoid:LoadAnimation(script.Animation)
anim.Looped = true
anim:Play()
2 Likes

Datastore - Save animations.

local data = '' -- could be a table, although I'm not sure.
for name,animationId in pairs(Emotes:GetChildren()) do
 data.. = name..'|'..animationId..',' -- you can style the format to whatever you want it to look like.
end
-- would look like this after:
-- Wave|1234567,Dance|2345678,Dance2|3456789
-- Although players can exploit this, so try to filter "|" when the player is thinking of a name.

:SetAsync() - Write Data
:UpdateAsync() - Read & Write Data
:GetAsync() - Load the emotes saved.

local emotes = data:split(',') -- different emotes
local animName,animId = emotes:split('|')[1],emotes:split('|')[2]

I don’t know how you store animations added by the player, so try to understand what I did with my script.

I’ll try this out the best I can. But thank you!

Heres what I’ve done for stuff like this; have a folder in replicated storage that stores all the emotes. Then, save the players owned emotes to a table:

local OwnedEmotes = {}

Use a for loop to loop through all the emotes the player owns:

for _, emotes in pairs(player.EmoteFolder:GetChildren()) do
table.insert(OwnedEmotes, {
–the emote data here, prolly js like Name = emotes.Name
end})

Then when retrieving the players emotes when they join u can use the replicated storage folder and do smth like:

NewEmote = EmotesStorageFolder:WaitForChild(SavedEmotes.Name):Clone()

Then parent it to the players emote folder. I hope this makes sense, if u have any questions ill try to help u more

I understand a little more but I’m trying to make a system where the player can buy emotes and I’m a bit confused. I’ve looked around a bit on the forum and it’s said that you can’t save instances. Wouldn’t this system not save the players emotes through servers?

Well it would save that the player owns the emotes name, then u js clone the emote instance from a seperate spot in replicated storage

But yes, you would have to use data store service to actually save it