Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I need help with a Data Store expert here(Or someone good with it).. Please help!?

Asked by 6 years ago

I have been trying to do Data Stores for already a week and nothing is working. AND NO, THE WIKI DID NOT HELP. I have 2 scripts, one to save and one to load.

Here's the one to load:

game.Players.PlayerAdded:connect(function(player)
    print("Getting player information..")
    local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Stats")
    wait(15)
    print("Player information loaded succesfully!")
    player:WaitForChild("leaderstats")
    wait(1)
    Instance.new("IntValue",player.Character:WaitForChild("PlayerSkins"))
    local stats = player.Character:WaitForChild("PlayerSkins"):GetChildren()
    print("Loading stats...")
    pcall(function()
    for i = 1, #stats do 
    wait(1)
    stats[i].Value = datastore:GetAsync(stats[i].Name)
    stats[i].Name = datastore:GetAsync(stats[i].Value) 
    print(stats[i].Name.." Given succesfully!") --Prints "0 Given succesfully" Why this happens?
    wait(.1)
    end
    print("Stats succesfully loaded!")
    end)
end)

The script is in workspace. It prints stuff INCORRECTLY (Prints that it loaded 0 for the name and value).

And then there's the one to load:

local player = game.Players:GetPlayerFromCharacter(script.Parent)
repeat wait() until player.Character
player.Character:WaitForChild("BoughtSkin").OnServerEvent:connect(function()
    print("Auto saving...")
    wait(2)
    local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Stats")--Player key
local statstorage = player.Character:WaitForChild("PlayerSkins"):GetChildren()
pcall(function()
for i = 1, #statstorage do
    datastore:SetAsync(statstorage[i].Name, statstorage[i].Value) 
    print(statstorage[i].Name.." Saved succesfully!")
    wait(.1)
end
print("Succesfully saved!")
end)
end)

The script is in "StarterCharacterScripts" It prints the stuff correctly(Prints that it saved) But when there is the time to load, it loads 0 in the name and 0 in the value,idk why

I don't know why it loads 0.. Can somebody help me? I REALLY need help and I would give my Sincere thanks to whoever helps me. Thank you. :(

0
Wait till Kingdom5 gets on. He is the DataStore god. GottaHaveAFunTime 218 — 6y
0
I so hope so, that makes me relived.. Thanks. wilsonsilva007 373 — 6y
0
First off, if the second script is in StarterCharacterScripts, then the parent will be "PlayerScripts" So, it doesn't make sense to get the player from :GetPlayerFromCharacter(script.Parent) because, script.Parent is PlayerScripts.... Not to mention, it's on Client side, so you can't even get the player from the parent even if it was the player, because it takes a parameter of Character. KingLoneCat 2642 — 6y
0
:GetPlayerFromCharacter() takes a parameter of Character to get the player but, you can just use a local script and call local player to get the player. Second of all, the first script you use :GetAsync twice, which doesn't make sense. Just use :GetAsync() once and access the values from there. Data store does have a request limit btw. Also, the code is really messy and looks very inefficient, KingLoneCat 2642 — 6y
View all comments (5 more)
0
Like, in the first script you didn't set a variable for the value when you created it. Which didn't make sense to me. You made the value, then made a variable for it, you can just make a variable upon using Instance.new() with it. KingLoneCat 2642 — 6y
0
Whoa ^ greatneil80 2647 — 6y
0
simple explanation when player joins.. GetAsync(), when they leave, SetAsync() or if you don't want to use that... JSon:Encode / Decode greatneil80 2647 — 6y
0
You know you could put all that in an answer, right? o.o wilsonsilva007 373 — 6y
0
And I can get the player from StarterCharacterScripts because it is CharacterScripts and NOT PlayerScripts wilsonsilva007 373 — 6y

Answer this question