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

Why I can't storage IntValue to the DataStore?

Asked by 1 year ago
Edited 1 year ago

Hello!

I'm making a game, and I wrote a script, that creates a new IntValue for a leaderstats-folder (it's created already in another script). Value is counting player's minutes in the game. But some reason, it doesn't work. Here's the script:

local DataStoreService = game:GetService("DataStoreService")
local TimeData = DataStoreService:GetDataStore("TimeStats")

game:GetService("Players").PlayerAdded:Connect(function(player)          --Player joins the game

    local leaderstats = player:FindFirstChild("leaderstats")
    local Minutes = Instance.new("IntValue", leaderstats)               -- Creating new integer value for leaderstats

    Minutes.Name = "Minutes"                                            --
    Minutes.Value = 1                                                   -- Integer's properties
    Minutes.Value = TimeData:GetAsync(player.UserId)                    --


    local Data = TimeData:GetAsync(player.UserId)
    if Data then    
        Minutes.Value = Data                                            -- Minute's value = player's data
    end

    local alwtrue = true                                                -- always true :)

    repeat                                                              -- looping forever
        wait(60)
        Minutes.Value = Minutes.Value + 1
    until
    alwtrue == false

end)

game:GetService("Players").PlayerRemoving:Connect(function(player)  
    TimeData:SetAsync(player.UserId, player.leaderstats.Minutes.Value)  -- Storaging data

end)

Everytime I get the same error:

Minutes is not a valid member of Folder "Players.____.leaderstats"  -  Server - Script:30

Answer this question