Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[Solved Sort of]Saving A Stringvalue with a datastore?

local dsService = game:GetService("DataStoreService")
local ds = dsService:GetDataStore("DataStored")

local function statChange(playerId, views, subs, cash , diamonds,Pc)
    print("Stats Changed")
    local playerData = {views.Value, subs.Value, cash.Value, diamonds.Value,Pc.Value}
    ds:SetAsync(playerId, playerData)
end

game.Players.PlayerAdded:Connect(function(plr)
    --NumberData--
    local folder = Instance.new("Folder",plr)
    folder.Name = "leaderstats"


    local Subs = Instance.new("IntValue",folder)
    Subs.Name = "Subs"


    local Views = Instance.new("IntValue",folder)   
    Views.Name = "Views"

    local Cash = Instance.new("IntValue",folder)   
    Cash.Name = "Cash"

    local Diamonds = Instance.new("IntValue",folder)   
    Diamonds.Name = "Diamonds"
    --Build Data--
    local saves = Instance.new("Folder",plr)
    saves.Name = "saves"
    --Pc--
    local Pc = Instance.new("StringValue",folder)
    Pc.Name = "Pc"
    Pc.Value = "Pc1"

    local playerData = ds:GetAsync(plr.UserId) or nil
    print(playerData)

    local playerData = ds:GetAsync(plr.UserId) or nil
    print(playerData)


    if playerData then
        Views.Value = playerData[1]
        Subs.Value = playerData[2]
        Cash.Value = playerData[3]
        Diamonds.Value = playerData[4]
        Pc.Value = playerData[5]
    end
    Subs.Changed:Connect(function()
        print("Works")
        statChange(plr.UserId, Views, Subs, Cash , Diamonds,Pc)
    end)    
    Views.Changed:Connect(function()
        statChange(plr.UserId, Views, Subs, Cash, Diamonds,Pc)
    end)
  Cash.Changed:Connect(function()
        statChange(plr.UserId, Views, Subs, Cash, Diamonds,Pc)
    end)
  Diamonds.Changed:Connect(function()
        statChange(plr.UserId, Views, Subs, Cash, Diamonds,Pc)
    end)
Pc.Changed:Connect(function()
        statChange(plr.UserId, Views, Subs, Cash, Diamonds,Pc)
    end)
  
end)



game:BindToClose(function()
wait(5) 
end)

So I got this datastore but Pc data doesn't display in the leaderboard its line 48 that's making the errors can somebody tell me what I did wrong and help me towards a solution.

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.