#Need help with datastores

6 messages · Page 1 of 1 (latest)

zinc stump
#

I watched a few tutorials and wrote this script for my game, It saves textbox text, It is outputting N/A and not setting what the player put in:

'''lua

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("MainMenuDataStore")

local Template = {
Text1 = "N/A",
Text2 = "N/A",
Text3 = "N/A",
Text4 = "N/A"
}

game.Players.PlayerRemoving:Connect(function(player)

Template.Text1 = player.PlayerGui.PlayGui.Frame.SaveSlot1Frame.NameLabel.Text                         <---- EMPHASIS ON THIS LINE

local sucess, err = pcall(function()
    local data = DataStore:GetAsync(player.UserId)
    print(data)
end)

if sucess then
    DataStore:SetAsync(player.UserId, Template)
else
    warn(err)
end

print(DataStore:GetAsync(player.UserId).Text1)

end)

game.Players.PlayerAdded:Connect(function(player)
pcall(function()
return DataStore:GetAsync(player.UserId)
end)
wait(0.5)
print(DataStore:GetAsync(player.UserId).Text1)
player.PlayerGui.PlayGui.Frame.SaveSlot1Frame.NameLabel.Text = DataStore:GetAsync(player.UserId).Text1
end)

lua'''

upbeat cloudBOT
#

studio** You are now Level 2! **studio

static venture
#

try using a for loop and try to set the specific index, value pair to the text you want to save

#

create a separate function for the for loop, better organized that way. Then reference the function where the emphasis line is.

limber crest
#

😦

#

Use profileservice