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

currentTime is not a valid member of Folder?

I am trying to get a Datastore. and when i try this:

local ds = game:GetService("DataStoreService"):GetDataStore("datastore") --not my real datastore name. just for privacy
game.Players.PlayerAdded:Connect(function(plr)
	wait()
	local plrkey = "id_"..plr.userId
	local save1 = plr.leaderstats.currentTime  --Change to your stat
	local save2 = plr.leaderstats.maxTime

	local GetSaved = ds:GetAsync(plrkey)
	if GetSaved then
		save1.Value = GetSaved[1]
		save2.Value = GetSaved[2]
	else
		local NumberForSaving = {save1.Value, save2.Value}
		ds:GetAsync(plrkey, NumberForSaving)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	ds:SetAsync("id_"..plr.userId, {plr.leaderstats.currentTime.Value, plr.leaderstats.maxTime.Value})
end)

i get this error: 16:06:59.632 currentTime is not a valid member of Folder "Players.Sivan12345678.leaderstats"

please help :-:

2 comments

0

datastore names does nothing with privacy, you dont need to change it back though, also could you show the source code of you cloning leaderstats into player?

0

oh thats answered

2 answers

You either haven't made currentTime or you have to wait for it to be there.

local ds = game:GetService("DataStoreService"):GetDataStore("datastore") --not my real datastore name. just for privacy
game.Players.PlayerAdded:Connect(function(plr)
    wait()
    local plrkey = "id_"..plr.userId
    local save1 = plr.leaderstats:WaitForChild("currentTime") --Change to your stat
    local save2 = plr.leaderstats.maxTime

    local GetSaved = ds:GetAsync(plrkey)
    if GetSaved then
        save1.Value = GetSaved[1]
        save2.Value = GetSaved[2]
    else
        local NumberForSaving = {save1.Value, save2.Value}
        ds:GetAsync(plrkey, NumberForSaving)
    end
end)

game.Players.PlayerRemoving:Connect(function(plr)
    ds:SetAsync("id_"..plr.userId, {plr.leaderstats.currentTime.Value, plr.leaderstats.maxTime.Value})
end)

5 comments

0

but now there is Infinite yield possible on 'Players.Sivan12345678.leaderstats:WaitForChild("currentTime")'

0

its still not working ..

0

It's most likely because you haven't made something called currentTime in the leaderstats. You can make it by doing local ct = Instance.new("Intvalue") ct.Name = "currentTime" ct.Parent = "leaderstats"

0

i have.

0

but now the error is on game.Players.PlayerRemoving:Connect(function(plr) ds:SetAsync("id_"..plr.userId, {plr.leaderstats.currentTime.Value, plr.leaderstats.maxTime.Value}) end)

You need to create a new string value into leaderstats using a function called Instance.new as you do not have any variables inside of the leaderstats folder.

2 comments

0

So No intvalue?

0

No, for time you should use a string value

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