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

[Solved] Datastore either not saving or not getting data?

Asked by 4 years ago
Edited 4 years ago

i dont know why but my data store is not saving and/or loading my data, i change the values but when i press save it outputs:

--[[
  fired
  16:25:11.545 - Saved 49945523  for kie1605
  16:25:11.548 - Saved 49945523  for kie1605
  16:25:11.549 - Saved 49945523  for kie1605
  16:25:11.551 - Saved 49945523  for kie1605
  16:25:11.552 - Saved 49945523  for kie1605
  16:25:11.554 - Saved 49945523  for kie1605
  16:25:11.557 - Saved 49945523 0 for kie1605
  16:25:11.559 - Saved 49945523 0 for kie1605
  16:25:11.560 - Saved 49945523 0 for kie1605
  16:25:11.562 - Saved 49945523 0 for kie1605
  16:25:11.563 - Saved 49945523 0 for kie1605
]]--

like nothing gets saved

here's the script:

local Players = game:GetService("Players")

local DS = game:GetService("DataStoreService")
local PlayerData = DS:GetDataStore("PlayerData")


local function NewPlayerData(player)
    local NewData = Instance.new("Folder", player)
    NewData.Name = "PlayerData"

    for _, Stats in pairs(script.PlayerData:GetChildren()) do
        local NewStats = Instance.new(Stats.ClassName, NewData)
        NewStats.Name = Stats.Name
    end
end


local function LoadData(player)
    NewPlayerData(player)

    local Chakra1
    local Chakra2
    local Chakra3
    local Chakra4
    local Chakra5
    local Clan
    local Attack
    local Agility
    local Defence
    local ChakraLevel
    local ChakraControl

    local success, err = pcall(function()
        Chakra1 = PlayerData:GetAsync("Chakra1: "..player.UserId)
        Chakra2 = PlayerData:GetAsync("Chakra2: "..player.UserId)
        Chakra3 = PlayerData:GetAsync("Chakra3: "..player.UserId)
        Chakra4 = PlayerData:GetAsync("Chakra4: "..player.UserId)
        Chakra5 = PlayerData:GetAsync("Chakra5: "..player.UserId)   
        Clan = PlayerData:GetAsync("Clan: "..player.UserId)     
        Attack = PlayerData:GetAsync("Attack: "..player.UserId) 
        Agility = PlayerData:GetAsync("Agility: "..player.UserId)   
        Defence = PlayerData:GetAsync("Defence: "..player.UserId)   
        ChakraLevel = PlayerData:GetAsync("ChakraLevel: "..player.UserId)   
        ChakraControl = PlayerData:GetAsync("ChakraControl: "..player.UserId)
    end)

    if not success then
        warn("Data could not load for "..player.Name)
        warn(err)
        return
    else
        print(Chakra1)
        print(Chakra2)
        print(Chakra3)
        print(Chakra4)
        print(Chakra5)
        print(Clan)
        print(Attack)
        print(Agility)
        print(Defence)
        print(ChakraLevel)
        print(ChakraControl)
        player.PlayerData.Chakra1.Value = Chakra1
        player.PlayerData.Chakra2.Value = Chakra2
        player.PlayerData.Chakra3.Value = Chakra3
        player.PlayerData.Chakra4.Value = Chakra4
        player.PlayerData.Chakra5.Value = Chakra5
        player.PlayerData.Clan.Value = Clan
        player.PlayerData.Attack.Value = Attack
        player.PlayerData.Agility.Value = Agility
        player.PlayerData.Defence.Value = Defence
        player.PlayerData.ChakraLevel.Value = ChakraLevel
        player.PlayerData.ChakraControl.Value = ChakraControl

    end
end

local function SaveData(player)
    local success, err = pcall(function()
        PlayerData:SetAsync("Chakra1: "..player.UserId, player.PlayerData.Chakra1.Value)
        PlayerData:SetAsync("Chakra2: "..player.UserId, player.PlayerData.Chakra2.Value)
        PlayerData:SetAsync("Chakra3: "..player.UserId, player.PlayerData.Chakra3.Value)
        PlayerData:SetAsync("Chakra4: "..player.UserId, player.PlayerData.Chakra4.Value)
        PlayerData:SetAsync("Chakra5: "..player.UserId, player.PlayerData.Chakra5.Value)
        PlayerData:SetAsync("Clan: "..player.UserId, player.PlayerData.Clan.Value)
        PlayerData:SetAsync("Attack: "..player.UserId, player.PlayerData.Attack.Value)
        PlayerData:SetAsync("Agility: "..player.UserId, player.PlayerData.Agility.Value)
        PlayerData:SetAsync("Defence: "..player.UserId, player.PlayerData.Defence.Value)
        PlayerData:SetAsync("ChakraLevel: "..player.UserId, player.PlayerData.ChakraLevel.Value)
        PlayerData:SetAsync("ChakraControl: "..player.UserId, player.PlayerData.ChakraControl.Value)
    end)

    if not success then
        warn("Data could not be saved for "..player.Name)
        warn(err)
        return
    else
        warn("Saved "..player.UserId, player.PlayerData.Chakra1.Value.." for "..player.Name)
        warn("Saved "..player.UserId, player.PlayerData.Chakra2.Value.." for "..player.Name)
        warn("Saved "..player.UserId, player.PlayerData.Chakra3.Value.." for "..player.Name)
        warn("Saved "..player.UserId, player.PlayerData.Chakra4.Value.." for "..player.Name)
        warn("Saved "..player.UserId, player.PlayerData.Chakra5.Value.." for "..player.Name)
        warn("Saved "..player.UserId, player.PlayerData.Clan.Value.." for "..player.Name)
        warn("Saved "..player.UserId, player.PlayerData.Attack.Value.." for "..player.Name)
        warn("Saved "..player.UserId, player.PlayerData.Agility.Value.." for "..player.Name)
        warn("Saved "..player.UserId, player.PlayerData.Defence.Value.." for "..player.Name)
        warn("Saved "..player.UserId, player.PlayerData.ChakraLevel.Value.." for "..player.Name)
        warn("Saved "..player.UserId, player.PlayerData.ChakraControl.Value.." for "..player.Name)
    end
end

Players.PlayerAdded:Connect(function(player)
    LoadData(player)
end)

game:GetService("ReplicatedStorage").RemoteEvents.RemoteEvent.OnServerEvent:Connect(function(player)
    print("fired")
    SaveData(player)
end)
0
hello? kie1605 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

i found a work around with remotes

Ad

Answer this question