How To SAVE Objects With DataStores | Roblox Studio Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 17 พ.ย. 2024

ความคิดเห็น • 107

  • @zblox164
    @zblox164  ปีที่แล้ว +3

    I hope this video has helped in some way. If you have any questions or problems, join the discord server: discord.gg/xJB2Adu4cr. Another way to reach me for dev support related questions is to @ me in a dev forum post. Thanks for watching, hope it helped!

  • @Ernad1
    @Ernad1 8 หลายเดือนก่อน +2

    EVERYTHING ELSE WAS SO CONFUSING, THIS HELPED SO GOD DAMN MUCH. THANK YOU KIND SOUL 😭😭

  • @wyeoak
    @wyeoak ปีที่แล้ว +6

    great tutorial! personally, i used setasync() instead of updateasync() because of updateasync being slower and sending more api requests.
    to anyone reading this, keep this in mind!

    • @landor1518
      @landor1518 ปีที่แล้ว +1

      I've personally never head of updateasync lol

    • @АртёмДолгоруков-ж3ш
      @АртёмДолгоруков-ж3ш ปีที่แล้ว +2

      Me too used a long time ago SetAsync... Some players lost they Data. With UpdateAsync no one isn't lost Data

  • @bigfloppingtaco
    @bigfloppingtaco 26 วันที่ผ่านมา +2

    I was really confused on how to save non values to datastores, thank you so much!

  • @SunsetGacha2008
    @SunsetGacha2008 19 วันที่ผ่านมา

    I was thinking this would take like 300 lines of code.. you saved my game thank you

  • @JUGNATIONNN
    @JUGNATIONNN 11 หลายเดือนก่อน +2

    ty i used to not know how to do datastore for folder i used to think it was so consufing and i finally did it (lil dif frm urs it was just a plr folder i put there and yea) tysm 👍

  • @HYP.3R_
    @HYP.3R_ 3 หลายเดือนก่อน

    oml frigging thank you. ive been searching for this FOR HOURSSSS!!!!
    i frigging luv u
    words cannot express how much pain and suffering i was in for THESE YEARS
    i frigging luv u

  • @hike8932
    @hike8932 ปีที่แล้ว +2

    i actually use this technique for important objects like a custom block a player made in a game

  • @Screen-v4q
    @Screen-v4q 8 หลายเดือนก่อน

    a great sequal to the placement series

  • @KraKenDevYT
    @KraKenDevYT 10 หลายเดือนก่อน +1

    Greatly explained, easy to understand!

  • @onlyyt8674
    @onlyyt8674 ปีที่แล้ว +2

    Man u are so underrated I am in love with ur tutorials

  • @Aqua_Turneur
    @Aqua_Turneur ปีที่แล้ว +2

    Thank you so much! This is exactly what i needed for my game!

  • @jedinoah5370
    @jedinoah5370 6 หลายเดือนก่อน

    I recently came up with an idea for a tycoon sort of game and needed this to save what the player bought.

  • @oskard3516
    @oskard3516 ปีที่แล้ว +7

    FINNALY THANK YOUU

  • @DavidWilsonJr
    @DavidWilsonJr ปีที่แล้ว +3

    I’ve been doing this the long way around for too long… 😒 Thank you for the lesson!!

    • @zblox164
      @zblox164  ปีที่แล้ว +1

      Glad I could help you out!

  • @ImIndeedCappy
    @ImIndeedCappy 10 หลายเดือนก่อน +1

    The tutorial was really useful, thanks alot! Also, a type checking tutorial would be of great help!

  • @Smurfis
    @Smurfis ปีที่แล้ว +3

    You should go more in-depth with the placement system and this and make some form of housing system with a UI and such

  • @cangodev
    @cangodev ปีที่แล้ว +2

    This is an incredibly useful video, thanks!

  • @matrixgeg
    @matrixgeg 8 หลายเดือนก่อน +1

    thanks for the awesome tutorial

  • @STINKSPOP
    @STINKSPOP 6 หลายเดือนก่อน

    bro summoned every tycoon / building game owners by this video.

  • @holtzapfel
    @holtzapfel ปีที่แล้ว +1

    I'm a fan of your OCD

  • @GabeioIDK
    @GabeioIDK 6 หลายเดือนก่อน

    thanks im making roblox inside of roblox and im adding a studio

  • @OverThere95
    @OverThere95 11 หลายเดือนก่อน +1

    can you implement a saving system into the placement system? it would really be helpful because i'm making a game kind of like mini cities. everything works I just need it to save but I don't know how to do it. if you had time to implement a saving system kind of like this but works with the placement system series you made, it would be awesome. thanks

  • @PinkyBoyStudios
    @PinkyBoyStudios ปีที่แล้ว +1

    THANK YOU!

  • @NeverEverFaceTheDark
    @NeverEverFaceTheDark 11 หลายเดือนก่อน +1

    aha, thank you, this is very well explained. I think im missing some context: am i right in thinking that this solution would be useful when making a placement system (of parts)? right now however, the relevant parts are in the datahandler... would i be correct thinking that 1. this is the place a placement system would save parts to? (which then are saved to the datastore when a player leaves) 2. if you wanted parts to not be linked to a player so much as to a server, then the starting signal shouldn't be playeradded but server startup (if that is something that exists)? I have read quite a lot and watched videos on datastores, but not proficient yet, please excuse me if im not getting things right. thank you for your response in advance

  • @psalm1319
    @psalm1319 ปีที่แล้ว +1

    Thank you

  • @greng3911
    @greng3911 ปีที่แล้ว +1

    This was a great tutorial

  • @viktorscott8013
    @viktorscott8013 11 หลายเดือนก่อน

    This works but my statue becomes a plain part and the color isn't saved

  • @fizzinsoda
    @fizzinsoda หลายเดือนก่อน

    why arent you saving the obj's vector3's instead of each single position?

  • @IvandroidYT
    @IvandroidYT ปีที่แล้ว +1

    I love these videos

  • @alex342gwsturk8
    @alex342gwsturk8 10 หลายเดือนก่อน

    why do you need to put in the x y z seperately? cant we do obj.CFrame.Position instead of obj.CFrame.Position.X obj.CFrame.Position.Y obj.CFrame.Position.Z?

  • @SkilledIm
    @SkilledIm 4 หลายเดือนก่อน

    i get error:
    DataStoreService: CantStoreValue: Cannot store Array in data store. Data stores can only accept valid UTF-8 characters. API: UpdateAsync, Data Store: SBGObjectsData

  • @toastedstuff
    @toastedstuff 6 วันที่ผ่านมา

    HELP! attempt to index nil with UserId

  • @360sauce7
    @360sauce7 5 หลายเดือนก่อน

    Profile Service 🗿🍷

  • @Spiffybub
    @Spiffybub ปีที่แล้ว

    do how to save humanoid next, for example like "MaxHealth" etc

    • @mrputiton9017
      @mrputiton9017 ปีที่แล้ว +1

      Make a Value for a players health amount then make a DataStore for the Value then when the player joins the health amount is the same as the value

  • @EquidaeRoblox
    @EquidaeRoblox 2 หลายเดือนก่อน

    Does this work with complex models that are rigged with animations

  • @therealmrspeedy
    @therealmrspeedy ปีที่แล้ว +2

    Awesome! Is there away to save gui data. Like if someone wanted to mute music in the game and they go to the settings to turn it off then once they leave it saves it and when they join the music is muted.

    • @lovredev
      @lovredev ปีที่แล้ว +3

      You can save a boolean so True or False then retrieve that data when they join and if its True then enable the music, if its False then disable it. (Once player clicks music setting button fire an remote event to change the value in datastore, just make sure the arguments are Boolean so you just pass in True or False when firing.)

  • @Revoltition
    @Revoltition 11 หลายเดือนก่อน +9

    help, when saving the data, it says i cannot store array in data store and can only accept valid UTF-8 characters

    • @malachilast7521
      @malachilast7521 6 หลายเดือนก่อน +1

      Convert it to json ,wait I'm late to reply

    • @BloxProgrammingRBLX
      @BloxProgrammingRBLX 8 วันที่ผ่านมา

      just use instead of: obj.Color: obj.Color.R
      obj.Color.G
      obj.Color.B
      Wait im so late to reply

  • @alygamer2286
    @alygamer2286 11 หลายเดือนก่อน

    how can you save the brickcolor? i've tried many ways but it keeps on putting in the wrong type of color to each part. Could u please help me out? Please respond asap.

  • @n0tfares
    @n0tfares 8 หลายเดือนก่อน

    may you tell me how do you run it by a gui like save button? if you press the button it will save your parts, also for the load button too and make multiple buttons for other buildings and different stuff

  • @scalewreck
    @scalewreck ปีที่แล้ว

    can you also just put obj.CFrame.Position instead of getting all the axis? same with the orientation?

  • @bluar.
    @bluar. 4 หลายเดือนก่อน

    any way to save size too? and color3.FromRGB

  • @Emilio.223
    @Emilio.223 11 หลายเดือนก่อน

    IS this possible with gui objects in a tag? Because i want to save the visibility of the gui object, in my case a button and a text label. But how can i achieve that?

  • @mejzs
    @mejzs 11 หลายเดือนก่อน

    Can anyone help me? I tryed this for my gui and it didnt work?

  • @Hedjiddbldvdo
    @Hedjiddbldvdo ปีที่แล้ว +1

    Tyyyy

  • @palomarechoncha369
    @palomarechoncha369 ปีที่แล้ว +1

    hey mate! Im a little nooby dev, wanted to ask how to save the position of a model inside a limited position like ex: a restaurant tycoon you place stuff and you save it bt there are dif spots and want them to spawn like you want to

    • @zblox164
      @zblox164  ปีที่แล้ว +2

      Do you mean saving positions relative to a plot? If so, what you can do is utilize the CFrame library to convert your positions to local space (aka object space). You can use the Inverse() method to convert the CFrame:
      for i, item in ipairs(plot.itemHolder:GetChildren()) do
      -- Get 'local' positions and rotation
      local objCFrame = plotCFrame:Inverse()*item.PrimaryPart.CFrame
      local _, angle = objCFrame:ToOrientation()
      -- Add values to table
      table.insert(data, {
      tostring(item),
      objCFrame.X,
      objCFrame.Y,
      objCFrame.Z,
      math.round(angle*(180/math.pi))
      })
      end
      That will save the data relative to the plot chosen. To load in, you can reverse the process by simply multiplying the plot CFrame and the objects CFrame to convert back to world coordinates:
      for i, item in ipairs(savedData) do
      local newItem = items:FindFirstChild(item[1]):Clone()
      if newItem then
      local x = item[2]
      local y = item[3]
      local z = item[4]
      local yAngle = item[5]*math.pi/180
      local angle = CFrame.fromEulerAnglesXYZ(0, yAngle, 0)
      local pos = plotCFrame*CFrame.new(x, y, z)
      newItem:PivotTo(pos*angle)
      end
      newItem.Parent = ITEM_LOCATION
      end
      This code won't work and is untested but that's the concept. Here are some more resources on the topic:
      create.roblox.com/docs/reference/engine/datatypes/CFrame#Inverse
      create.roblox.com/docs/building-and-visuals/studio-modeling/object-world-space
      create.roblox.com/docs/reference/engine/datatypes/CFrame#ToObjectSpace
      create.roblox.com/docs/reference/engine/datatypes/CFrame#ToWorldSpace
      You can also take a look at a video I made on this topic: th-cam.com/video/F413drdadDs/w-d-xo.html

    • @palomarechoncha369
      @palomarechoncha369 ปีที่แล้ว +1

      @@zblox164 you are my god

    • @zblox164
      @zblox164  ปีที่แล้ว

      @@palomarechoncha369 Glad I could help!

  • @HK_HOP
    @HK_HOP 7 หลายเดือนก่อน

    What if the part has a script inside?

  • @whitekingcat5118
    @whitekingcat5118 ปีที่แล้ว

    didn't work : ( like there are error everywhere in the script. I wish i could just copy and paste it so that it maybe don't have the errors

  • @ethanak0
    @ethanak0 ปีที่แล้ว

    Could you do a part 11 of the placement system tutorial that shows us how to implement horizontal placement?

    • @Smurfis
      @Smurfis ปีที่แล้ว +1

      Look for the IntValue 90 or the number in the CFrame in the rotate function and change it to 45 degrees :) assuming you used his plot system. Good luck c
      You could very much easily alter his code to do this simply.
      With little coding knowledge at all.

    • @Smurfis
      @Smurfis ปีที่แล้ว

      A better way would be to use a Enum key code like R to rotate and to display this as a icon and also use that same icon for mobile players to rotate hope this made sense
      What I mean is use the same code for the mobile button but change the function and the trigger for mobile inputs

  • @auzokozoffical
    @auzokozoffical 5 หลายเดือนก่อน

    yo could we see the whole script?

  • @aydintabakci9812
    @aydintabakci9812 ปีที่แล้ว

    is there any way you could save value's and then load the value in the same numbervalue?

  • @ibaadnstuff
    @ibaadnstuff ปีที่แล้ว

    how can i do this but with gui? for example i want my gui to become invisible and when the player rejoins its still invisible?

    • @zblox164
      @zblox164  ปีที่แล้ว

      For any object, assuming you want to reconstruct it, you just take the components you want to save and add them into a table. In your case, if you're just needing to save a value of the GUI's visibility, you can actually just save either the Enabled property on the ScreenGui or the Visible property on the frame that contains the UI elements since they are a boolean value.

  • @ShadowkingX
    @ShadowkingX ปีที่แล้ว

    I need to get the color(hsv) from a mesh part. How do I get the hue sat and Val?

  • @keyhitt952
    @keyhitt952 ปีที่แล้ว

    there is a problem with the first script when ever i typed in "load" "save" it underlined it in red, i don't think the script works any more

    • @landor1518
      @landor1518 ปีที่แล้ว

      It always works, try checking for any mistakes.

  • @Ytkoh
    @Ytkoh ปีที่แล้ว

    hello, how can i save objects with scripts and other stuffs

  • @not_ducky2
    @not_ducky2 11 หลายเดือนก่อน

    what if the object has too many parts? a datastore key can only have 4 mb of data.

    • @zblox164
      @zblox164  11 หลายเดือนก่อน

      unless you are storing thousands of parts per object, you should be fine. If you do run into issues relating to the data limit, you will need to look into data compression.

  • @yarik_superpro
    @yarik_superpro 7 หลายเดือนก่อน

    a lot of yapping and code doesnt make sense sometimes.

  • @itsnoah4276
    @itsnoah4276 ปีที่แล้ว

    Hello, i have 1 problem idk if its just for me, but it did not save the size?

    • @reminderIknows
      @reminderIknows ปีที่แล้ว +1

      you never saved the size, I think it's quite easy to understand how to add size saving

  • @TQ5890Playz_YT
    @TQ5890Playz_YT ปีที่แล้ว

    Do you by any chance know how to do this with vehicles?

    • @landor1518
      @landor1518 ปีที่แล้ว

      You can only make create the position and orientation value of vehicles and then save them, if needed you can do more.

  • @qxxrd
    @qxxrd ปีที่แล้ว +1

    12:27, couldn't you just use the math.rad function?

    • @zblox164
      @zblox164  ปีที่แล้ว +1

      Yes, what I did was equivalent to using math.rad(). The reason I didn't use it was to show exactly what was going on. But yes, you are correct, you can simply use math.rad().

  • @CxrsedDev
    @CxrsedDev ปีที่แล้ว

    yo bro what should i do if i need to save a lot of folders and models(i creating a tycoon)
    cuz i cant write obj.CFrame and etc help me!

    • @zblox164
      @zblox164  ปีที่แล้ว

      For tycoons what I recommend doing is simply looping through the objects on the tycoon, save the models position using GetPivot() (or by using the primary part position), then save the model name. When the player rejoins, you can use the name to access the model, and use the PivotTo() method to place it on the plot using the saved values.

  • @ThatOnecat-m7q
    @ThatOnecat-m7q หลายเดือนก่อน

    Could you send me the script? Im too lazy to type lol

  • @Floppicus
    @Floppicus ปีที่แล้ว

    can you pls publish this script, it would be easyer

    • @slightlylessbigjimmy
      @slightlylessbigjimmy ปีที่แล้ว

      --Services
      local players = game:GetService("Players")
      local dataStoreService = game:GetService("DataStoreService")
      local dataStore = dataStoreService:GetDataStore ("InstanceSave")
      -- Variables
      local keyPrefix = "Player: "
      local parts = workspace.Parts
      --Functions
      local function save(player: Player)
      local key = keyPrefix .. tostring(player.UserId)
      local data = {}
      for i, obj: BasePart in ipairs (parts:GetChildren()) do
      table.insert(data, {
      obj.Name,
      obj.CanCollide,
      -- Position
      obj.CFrame.Position.X,
      obj.CFrame.Position.Y,
      obj.CFrame.Position.Z,
      -- Rotation
      obj.Orientation.X,
      obj.Orientation.Y,
      obj.Orientation.Z
      })
      end
      local success, err
      repeat
      success, err = pcall(function()
      dataStore:UpdateAsync(key, function()
      return data
      end)
      end)
      task.wait()
      until success
      if not success then
      warn("failed to save data".. tostring(err))
      end
      end
      local function load(player: Player)
      local key = keyPrefix .. tostring(player.UserId)
      local success, err
      local data
      repeat
      success, err = pcall(function()
      data = dataStore:GetAsync(key)
      end)
      until success or not player:FindFirstChild(player.Name)
      if not data then
      return
      end
      if success then
      for i, obj in ipairs(data) do
      local newPart = Instance.new("Part")
      newPart.Name = obj[1]
      newPart.CanCollide = obj[2]
      newPart.CFrame = CFrame.new(obj[3], obj[4], obj[5])
      newPart.CFrame *= CFrame.Angles(obj[6]*math.pi/180, obj[7]*math.pi/180, obj[8]*math.pi/180)
      newPart.Anchored = false
      newPart.TopSurface = Enum.SurfaceType.SmoothNoOutlines
      newPart.Parent = workspace
      end
      else
      warn("failed to load data: " .. tostring(err))
      end
      end
      --Signals
      players.PlayerAdded:Connect(load)
      players.PlayerRemoving:Connect(save)
      game:BindToClose(function()
      for i, plr: Player in ipairs(players:GetPlayers()) do
      save(plr)
      end
      end)

  • @channykun1790
    @channykun1790 ปีที่แล้ว +1

    Is there any way to save a model? On datastore

    • @zblox164
      @zblox164  ปีที่แล้ว

      To save every part within a model, you'd have to use the process shown in this video but on every object within a model. You can use GetDescendants() to run through all the parts in a model, save their components, and then load when needed.

    • @channykun1790
      @channykun1790 ปีที่แล้ว

      how do I load them on the same spot of a plot when the player has choosen a plot@@zblox164

    • @RTU_GAMES
      @RTU_GAMES 9 หลายเดือนก่อน

      -

  • @CreateWithAce
    @CreateWithAce ปีที่แล้ว

    Can you add copy and paste that would be helpfull

  • @4zzenn
    @4zzenn 2 หลายเดือนก่อน

    hey man im making a simulator nd the doors work perfectly, and when one player passes trough the door it goes away for the other players too. can you help me fix this please

  • @bruh3475
    @bruh3475 ปีที่แล้ว

    Can you Pls put the script in the description pls

  • @BlackVoidSlayer
    @BlackVoidSlayer 3 หลายเดือนก่อน

    10:49 what if our data is a number value?

  • @NemoNews2
    @NemoNews2 7 หลายเดือนก่อน

    did not work datastores make no sense

    • @NemoNews2
      @NemoNews2 7 หลายเดือนก่อน

      local players = game:GetService("Players")
      local dataStoreService = game:GetService("DataStoreService")
      local dataStore = dataStoreService:GetDataStore("InstanceSave")
      local keyPrefix = "Player: "
      local parts = players.player
      local function save (player: Player)
      local key = keyPrefix .. tostring(player.UserId)
      local data = {}

      for i, obj: StringValue in ipairs(parts:GetChildren()) do
      table.insert(data, {
      obj.Name,
      obj.Value,
      })
      end

      local success, err
      repeat
      success, err = pcall(function()
      dataStore:UpdateAsync(key, function()
      return data
      end)
      end)

      task.wait()
      until success

      if not success then
      warn("Failed to save" .. tostring(err))
      end
      end
      local function load(player: Player)
      local key = keyPrefix .. tostring(player.UserId)
      local success, err
      local data

      repeat
      success, err = pcall(function()
      data = dataStore:GetAsync(key)
      end)
      until success or not players:FindFirstChild(player.Name)

      if not data then return end
      if success then
      for i, obj in ipairs(data) do
      local newPart = Instance.new("StringValue")
      newPart.Name = obj[1]
      newPart.Value = obj[2]
      newPart.Anchored = true
      newPart.Parent = player
      end
      else
      warn("Failed to load data: " .. tostring(err))
      end
      end
      players.PlayerAdded:Connect(load)
      players.PlayerRemoving:Connect(save)
      game:BindToClose(function()
      for i, plr: Player in ipairs(players:GetPlayers()) do
      save(plr)
      end
      end)

    • @ASK444
      @ASK444 6 หลายเดือนก่อน

      @@NemoNews2 You're parenting the part to the player which is causing the part to not appear, instead parent it to a folder in workspace.

    • @360sauce7
      @360sauce7 5 หลายเดือนก่อน

      Just use profile service

  • @Mr_Lukan03
    @Mr_Lukan03 4 หลายเดือนก่อน

    team fake

  • @auzokozoffical
    @auzokozoffical 5 หลายเดือนก่อน

    i y

  • @deonne9043
    @deonne9043 ปีที่แล้ว

    ρгό𝔪σŞm

  • @lovredev
    @lovredev ปีที่แล้ว +1

    obj[6]*math.pi/180 could just be math.rad(obj[6])

    • @zblox164
      @zblox164  ปีที่แล้ว +1

      Yes. The reason I didn't do that was to show exactly what was going on. But yes both are equivalent.