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

This is for a time saving script but an error hapens?

code :

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

game.Players.PlayerAdded:Connect(function(Player)
    local Leaderstats = Instance.new("Folder")
    Leaderstats.Name = "leaderstats"
    Leaderstats.Parent = Player
    local Minutes = Instance.new("IntValue")
    Minutes.Name = "Time Worshipping"
    Minutes.Value = 0
    Minutes.Parent = Leaderstats
    
    local Data = DataStore:GetAsync(Player.UserId)
    if Data then
        Minutes.Value = Data
    end
    
    coroutine.resume(coroutine.create(function()
        while true do
            wait(1)
            Minutes.Value = Minutes.Value + 1
        end
    end))
end)

game.Players.PlayerRemoving:Connect(function(Player)
    DataStore:SetAsync(Player.UserId, Player.leaderstats.Time_Worshipping.Value)
end)

Error i get = Time_Worshipping is not a valid member of Folder 01:11:57.384 - Stack Begin 01:11:57.384 - Script 'Workspace.Minute Leaderboard (Saves)', Line 27 01:11:57.385 - Stack End

Any help would really be appreciated thx

1 answer

The problem is that you used Time_Worshipping instead of Time Worshipping:

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

game.Players.PlayerAdded:Connect(function(Player)
    local Leaderstats = Instance.new("Folder")
    Leaderstats.Name = "leaderstats"
    Leaderstats.Parent = Player
    local Minutes = Instance.new("IntValue")
    Minutes.Name = "Time Worshipping"
    Minutes.Value = 0
    Minutes.Parent = Leaderstats

    local Data = DataStore:GetAsync(Player.UserId)
    if Data then
        Minutes.Value = Data
    end

    coroutine.resume(coroutine.create(function()
        while true do
            wait(1)
            Minutes.Value = Minutes.Value + 1
        end
    end))
end)

game.Players.PlayerRemoving:Connect(function(Player)
    DataStore:SetAsync(Player.UserId, Player.leaderstats["Time Worshipping"].Value) -- you need to write exactally the name
end)

2 comments

0

I don't think there's supposed to be a dot at Player.leaderstats. < there["Time Worshipping"]

0

ooops, forgot to remove it

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