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

"rebirths is not a valid member of Folder" why do i get this error?

im making a savegame thing for my game but i keep getting the error mentioned in the title on line 53

local dataStoreService = game:GetService("DataStoreService")
local karenDataStore = dataStoreService:GetDataStore("karenDataStore")

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local rebirths = Instance.new("IntValue",leaderstats)
    rebirths.Name = "Rebirths"
	rebirths.Value = 0
	rebirths.Parent = player.leaderstats
	
	local level = Instance.new("IntValue",leaderstats)
    level.Name = "Level"
	level.Value = 1
	level.Parent = player.leaderstats

    local cash = Instance.new("IntValue",leaderstats)
	cash.Name = "Cash"
	cash.Value = 0
	cash.Parent = player.leaderstats

    	
	


	local success, errormessage = pcall(function()
		datarebirths = karenDataStore:GetAsync(player.UserId,"-rebirths")
        datalevel = karenDataStore:GetAsync(player.UserId,"-level")
		datacash = karenDataStore:GetAsync(player.UserId,"-cash")
		
		print("data call succesful")
	end)
	
	
end)
game:BindToClose(function() -- This code will run BEFORE the game closes, in other words the game cannot close until this code has ended
	
	for _, player in pairs(game.Players:GetPlayers()) do -- loops through the players to get the player
	 
		local success, errormessage = pcall(function()
			karenDataStore:SetAsync(player.UserId.."-rebirths",player.leaderstats.rebirths.Value)
	        karenDataStore:SetAsync(player.UserId.."-level",player.leaderstats.level.Value)
			karenDataStore:SetAsync(player.UserId.."-cash",player.leaderstats.cash.Value)
			
	        print("working")
	    end)
		if success then
	        print ("Data Saved")	
	    else
	        print("Error, i am now sentient human")
	        warn(errormessage)
	    end
	
	end
end)

2 answers

✓ Accepted answer
local dataStoreService = game:GetService("DataStoreService")
local karenDataStore = dataStoreService:GetDataStore("karenDataStore")

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local rebirths = Instance.new("IntValue",leaderstats)
    rebirths.Name = "Rebirths"
    rebirths.Value = 0
    rebirths.Parent = leaderstats --Changed it to the instance shortcut

    local level = Instance.new("IntValue",leaderstats)
    level.Name = "Level"
    level.Value = 1
    level.Parent = leaderstats --Changed it to the instance shortcut

    local cash = Instance.new("IntValue",leaderstats)
    cash.Name = "Cash"
    cash.Value = 0
    cash.Parent = leaderstats --Changed it to the instance shortcut





    local success, errormessage = pcall(function()
        datarebirths = karenDataStore:GetAsync(player.UserId,"-rebirths")
        datalevel = karenDataStore:GetAsync(player.UserId,"-level")
        datacash = karenDataStore:GetAsync(player.UserId,"-cash")

        print("data call succesful")
    end)


end)
game:BindToClose(function() -- This code will run BEFORE the game closes, in other words the game cannot close until this code has ended

    for _, player in pairs(game.Players:GetPlayers()) do -- loops through the players to get the player

        local success, errormessage = pcall(function()
            karenDataStore:SetAsync(player.UserId.."-rebirths",player.leaderstats.Rebirths.Value) -- Capitalization
            karenDataStore:SetAsync(player.UserId.."-level",player.leaderstats.Level.Value) -- Capitalization
            karenDataStore:SetAsync(player.UserId.."-cash",player.leaderstats.Cash.Value) -- Capitalization

            print("working")
        end)
        if success then
            print ("Data Saved")    
        else
            print("Error, i am now sentient human")
            warn(errormessage)
        end

    end
end)

kk so this isnt the best way to make a datastore but ill show you what you did wrong with -- and ima fix it accept if helps

I am not sure, check capitalization because you change rebirths name to "Rebirths" and later in the script you state it as rebirths instead of "Rebirths"

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