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

My datastore script seems to not work, can anyone please help me fix my datastore script?

Asked by 7 years ago
Edited 7 years ago

I can't seem to get this script going.

01local DSS = game:GetService("DataStoreService") -- Getting the service
02local HeavySet = DSS:GetDataStore("HeavySet", "Players") -- Getting the storage
03 
04game.Players.PlayerAdded:connect(function(plr) -- When a player Joins
05    wait(5)
06    print("Loading in "..plr.Name.."s Items") -- Printing that it is loading in
07    local Key = plr.UserId
08    local MainGui = plr.PlayerGui:WaitForChild("MainGui") -- The Gui that has the values for the datastore to save
09    MainGui:WaitForChild("Items").HeavySet.Value = HeavySet:GetAsync(Key) -- Setting the value of the Heavy Set
10    HeavySet:SetAsync(Key, MainGui:WaitForChild("Items").HeavySet.Value) -- Save the value just in case
11    print("Loaded in Items") -- print that it has loaded it in
12end)
13 
14game.Players.PlayerRemoving:connect(function(plr)
15    print("Saving "..plr.Name.."s Items") -- print that it's going to save
16    local Key = plr.UserId
17    local MainGui = plr.PlayerGui:WaitForChild("MainGui") -- The Gui that has the values for the datastore to save
18    HeavySet:SetAsync(Key, MainGui:WaitForChild("Items").HeavySet.Value) --Saving the value
19    print("Saved Items") -- print that it has successfully saved
20end)

Please I beg someone to answer this question please!

0
Server scripts can't access a PlayerGui. Store the values inside the player, but not in the PlayerGui. UgOsMiLy 1074 — 7y

Answer this question