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

Data Stores don't seem to be working?

Asked by 5 years ago

So I'm having troubles with data stores despite the print debugging method working fully through. There seem to be no errors in output either. The script is in a folder in ServerScriptService.

local DSService = game:GetService("DataStoreService"):GetDataStore("KytesSave")
local PlayersLeft = 0

game.Players.PlayerAdded:Connect(function(player)
    PlayersLeft = PlayersLeft + 1
    local Kytes = Instance.new("IntValue")
    Kytes.Name = "Kytes"
    Kytes.Value = 0
    Kytes.Parent = player
    local player_data
pcall (function()
    player_data = DSService:GetAsync(player.UserId.."-Kytes")
end)

if player_data ~= nil then
    Kytes.Value = player_data
else
    Kytes.Value = 0
end
end)

local bindableEvent = Instance.new('BindableEvent')

game.Players.PlayerRemoving:Connect(function(player)
    pcall(function()
        DSService:SetAsync(player.UserId..'-Kytes', player.Kytes.Value)
        print("Saved")
        PlayersLeft = PlayersLeft - 1
        bindableEvent:Fire()
    end)
end)

game:BindToClose(function()
    while PlayersLeft > 0 do
        bindableEvent.Event:Wait()
    end
end)
0
What is it your trying to save? I don't understand.... Please explain what you are trying to do voidofdeathfire 148 — 5y
0
I'm trying to save the "Kytes" value, the currency of the game. itchymoonfire 179 — 5y
0
On line #26 {player.Kytes.Value}, On Line #16 {player_data[1]} User#26586 0 — 5y
0
Pretty sure Datastore only accepts tables and not values User#26586 0 — 5y

Answer this question