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

Why won't this work? (Save BoolValue on server)

Asked by
Drakyd 1
5 years ago

Hey guys! I'm trying to figure why doesn't this save script work. It doesnt send any error back but the value is set to false each time I rejoin/test the game

local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService") -- Getting data store service

Players.PlayerAdded:connect(function(player)
    local TrackersData = DataStoreService:GetDataStore(player.UserId.."Trackers") -- Getting data store
    local LevelTracker = Instance.new("Folder")
    LevelTracker.Parent = player
    LevelTracker.Name = "LevelTracker"
    local Level1 = Instance.new("BoolValue")
    Level1.Parent = LevelTracker
    Level1.Name = "Level1"
    Level1.Value = false
    local Value = TrackersData:GetAsync("Level1") -- Getting value from data store "TrackersData"
    if Value == nil then
       TrackersData:SetAsync("Level1",false) -- if value equals nothing then it'll creates it.
    else
       Level1.Value = Value
    end
end)

1 answer

Log in to vote
0
Answered by
karlo_tr10 1233 Moderation Voter
5 years ago

First of all you should use Pcall when you are using datastores. Problem is that you are never saving the data. Only time you set data is if player doesn't have data in the datastore. You will have to save data before player leaves or at certain interval.

1
You're supposed to add those changes and give him the general idea of where everything goes. KDarren12 705 — 5y
0
I suppose, not "supposed to". Maybe it's just a good way that's going around? KDarren12 705 — 5y
0
Oh boy I cant figure... Drakyd 1 — 5y
0
KDarren12 I think it's pointless to explain how to save data as that question has been answered multiple times. I was just pointing out the problem that he has got. karlo_tr10 1233 — 5y
Ad

Answer this question