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 6 years ago
Edited 6 years ago

I can't seem to get this script going.

local DSS = game:GetService("DataStoreService") -- Getting the service
local HeavySet = DSS:GetDataStore("HeavySet", "Players") -- Getting the storage

game.Players.PlayerAdded:connect(function(plr) -- When a player Joins
    wait(5)
    print("Loading in "..plr.Name.."s Items") -- Printing that it is loading in
    local Key = plr.UserId
    local MainGui = plr.PlayerGui:WaitForChild("MainGui") -- The Gui that has the values for the datastore to save
    MainGui:WaitForChild("Items").HeavySet.Value = HeavySet:GetAsync(Key) -- Setting the value of the Heavy Set
    HeavySet:SetAsync(Key, MainGui:WaitForChild("Items").HeavySet.Value) -- Save the value just in case
    print("Loaded in Items") -- print that it has loaded it in
end)

game.Players.PlayerRemoving:connect(function(plr)
    print("Saving "..plr.Name.."s Items") -- print that it's going to save
    local Key = plr.UserId
    local MainGui = plr.PlayerGui:WaitForChild("MainGui") -- The Gui that has the values for the datastore to save
    HeavySet:SetAsync(Key, MainGui:WaitForChild("Items").HeavySet.Value) --Saving the value
    print("Saved Items") -- print that it has successfully saved
end)

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 — 6y

Answer this question