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

Is it impossible to save "StringValue" through DataStore?

Asked by 6 years ago
Edited 6 years ago

I won't my datastore to save "StringValue" is it unsupported or it is a script error it just changes it to a number?

Server Script:

--DataStores
local DataStore = game:GetService("DataStoreService")
local DataStore_oofs = DataStore:GetDataStore("SaveSystem_oofs")
local DataStore_rank = DataStore:GetDataStore("SaveSystem_rank")

--Create leaderboard
game.Players.PlayerAdded:Connect(function(player)
    --Create Leaderboard
    local LeaderBoard = Instance.new("Folder",player)
    LeaderBoard.Name = "leaderstats"
    --Create Values
    local Oofs = Instance.new("NumberValue",LeaderBoard)
    Oofs.Name = "Oofs"
    Oofs.Value = 0
    local Rank = Instance.new("StringValue",LeaderBoard)
    Rank.Name = "Rank"
    Rank.Value = "New Oofer"
    wait(1)
    --Load
    Oofs.Value = DataStore_oofs:GetAsync(player.UserId, Oofs.Value)
    Rank.Value = DataStore_rank:GetAsync(player.UserId, Rank.Value)
end)

--Save Data
game.Players.PlayerRemoving:Connect(function(player)
    --Varibles
    local Oofs = player.leaderstats.Oofs
    local Rank = player.leaderstats.Rank
    --Save
    DataStore_oofs:SetAsync(player.UserId, Oofs.Value)
    DataStore_rank:SetAsync(player.UserId, Rank.Value)
end)

If there is a way to save string values, please explain?

0
Although your datastore setup isnt "wrong" i highly recommend looking into tables! You wont regret it. DinozCreates 1070 — 6y

2 answers

Log in to vote
1
Answered by
fr2013 88
6 years ago

If the player is added, then it would get a sync to the strings after dying I guess. So insert this inside game.Players.PlayerAdded:Connect(function(player) and replace it with the other GetASync

local InStudio = game:GetService("RunService"):IsStudio()

if not InStudio then
        Oofs.Value = DataStore_oofs:GetAsync(tostring(player.userId)) or 0
        Rank.Value = DataStore_rank:GetAsync(tostring(player.userId)) or "New Oofer"
    else
        Oofs.Value = DataStore_oofs
        Rank.Value = DataStore_rank
    end
Ad
Log in to vote
0
Answered by
Shadrz 40
6 years ago
Edited 6 years ago

This is probably the solution.

--DataStores
local DataStore = game:GetService("DataStoreService")
local DataStore_oofs = DataStore:GetDataStore("SaveSystem_oofs")
local DataStore_rank = DataStore:GetDataStore("SaveSystem_rank")

--Create leaderboard
game.Players.PlayerAdded:Connect(function(player)
    local key = "id_" .. player.UserId
    --Create Leaderboard
    local LeaderBoard = Instance.new("Folder",player)
    LeaderBoard.Name = "leaderstats"
    --Create Values
    local Oofs = Instance.new("NumberValue",LeaderBoard)
    Oofs.Name = "Oofs"
    Oofs.Value = 0
    local Rank = Instance.new("StringValue",LeaderBoard)
    Rank.Name = "Rank"
    Rank.Value = "New Oofer"
    wait(1)
    --Load
    if DataStore_oofs:GetAsync(player.UserId) and DataStore_rank:GetAsync(player.UserId) then
        Oofs.Value = DataStore_oofs:GetAsync(key)
        Rank.Value = DataStore_rank:GetAsync(key)
    else
    return
    end
end)

--Save Data
game.Players.PlayerRemoving:Connect(function(player)
    local key = "id_" .. player.UserId
    --Varibles
    local Oofs = player.leaderstats.Oofs
    local Rank = player.leaderstats.Rank
    --Save
    DataStore_oofs:SetAsync(key, Oofs.Value)
    DataStore_rank:SetAsync(key, Rank.Value)
end)

Answer this question