Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How Do I Access Datastore2 Data?

I've made character creation GUI that stores your customised style and saves it. I want to take the saved data from the datastore so I don't have to customise my character again. How can I go about this? Also this is a server script

local DataStore2 = require(1936396537)

DataStore2.Combine("Customization", "Shirt", "Pants")

local function getData(player)

    local char = player.Character or player.CharacterAdded:Wait()
    local ShirtDS = DataStore2("Shirt")
    local shirt = char:WaitForChild("Shirt")

    shirt.ShirtTemplate = ShirtDS:Get()
end

getData()

Only error is: ServerScriptService.DataStore:7: attempt to index local 'player' (a nil value) Line 7 Maybe access the player in another way?

1 answer

local DataStore2 = require(1936396537)

DataStore2.Combine("Customization", "Shirt", "Pants")

local function getData()
local player = game.Player.LocalPlayer

    local char = player.Character or player.CharacterAdded:Wait()
    local ShirtDS = DataStore2("Shirt")
    local shirt = char:WaitForChild("Shirt")

    shirt.ShirtTemplate = ShirtDS:Get()
end

getData()

1 comment

0

wont work as this would only work on a local script, which mine is a server script

This discussion is preserved as it was. New answers, comments, and votes are closed.