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

Trying to save Value to DataStore, Please help?

Asked by 3 years ago
Edited 3 years ago

Hi, I'm trying to save a value to my datastore, When I run the script it says nothing. Help?

Script is in serverscriptservice and FE is on.

Pic of output:

https://prnt.sc/ujsn6x

if you want to, just give me a working script with my variables instead of attempting to fix this one

local players = game:GetService("Players")

local Workpace = game:GetService("Workspace")

local DataStoreService = game:GetService("DataStoreService")

local StrengthData = DataStoreService:GetDataStore("StrengthData")


players.PlayerAdded:Connect(function(plr)
wait(3)

local strength = plr.PlayerGui.Points:WaitForChild("PointDisplay")


    local data
    local success, errormessage = pcall(function()
    StrengthData:GetAsync(plr.UserId.."-Strength")
    end)    
    if success then
        strength.StrengthValue.Value = data
    else
        warn(errormessage)
        print("couldnt get the data")
    end

end)



players.PlayerRemoving:Connect(function(plr)


local success, errormessage = pcall(function()

StrengthData:SetAsync(plr.UserId.."-Strength", plr.PlayerGui.Points.PointDisplay.StrengthValue.Value)



    end)

    if success then

print("Strength Saved")

    else
        print("Error when saving data")
        warn(errormessage)
    end


end)


0
It could be possible that the PlayerAdded script is being ran after the player is added, therefore not running. moo1210 587 — 3y
0
its wrapped in a p-call tho brodywth 97 — 3y
0
also, i wouldnt be able to access the gui without the wait brodywth 97 — 3y

Answer this question