Folder name isn't changing

I’m making a speedrun game, I store all of your best times in an int value inside of a folder in the player. I’ve just added new stages so I had to create 4 more folders with int values inside of it. Now, I’m getting this error message whenever I run the game Stage4 is not a valid member of Folder “Players.Coder_Tom.Times”, even though there is this part in the script: (Full script below)

	local Stage4 = Instance.new("Folder", Times)
	Stage4.Name = "Stage4"
	
	local Stage4BestTime = Instance.new("IntValue", Stage4)
	Stage4BestTime.Name = "BestTime"
	Stage4BestTime.Value = 0
	```

Full script:
```lua
local mps = game:GetService("MarketplaceService")
local dss = game:GetService("DataStoreService")
local dataStore = dss:GetDataStore("SaveAllPlayerData")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local Times = Instance.new("Folder", player)
	Times.Name = "Times"
	
	local Coins = Instance.new("IntValue", leaderstats)
	Coins.Name = "Coins"
	Coins.Value = 0
	
	local Level = Instance.new("IntValue", leaderstats)
	Level.Name = "Level"
	Level.Value = 1
	
	--[[
	Creating the stage values.
	--]]
	
	local Stage1 = Instance.new("Folder", Times)
	Stage1.Name = "Stage1"
	
	local Stage1BestTime = Instance.new("IntValue", Stage1)
	Stage1BestTime.Value = 0
	Stage1BestTime.Name = "BestTime"
	
	
	local Stage2 = Instance.new("Folder", Times)
	Stage2.Name = "Stage2"

	local Stage2BestTime = Instance.new("IntValue", Stage2)
	Stage2BestTime.Value = 0
	Stage2BestTime.Name = "BestTime"
	
	local Stage3 = Instance.new("Folder", Times)
	Stage3.Name = "Stage3"

	local Stage3BestTime = Instance.new("IntValue", Stage3)
	Stage3BestTime.Value = 0
	Stage3BestTime.Name = "BestTime"
	
	local Stage4 = Instance.new("Folder", Times)
	Stage4.Name = "Stage4"
	
	local Stage4BestTime = Instance.new("IntValue", Stage4)
	Stage4BestTime.Name = "BestTime"
	Stage4BestTime.Value = 0
	
	local Stage5 = Instance.new("Folder", Times)
	Stage5.Name = "Stage5"

	local Stage5BestTime = Instance.new("IntValue", Stage5)
	Stage5BestTime.Value = 0
	Stage5BestTime.Name = "BestTime"

	local Stage6 = Instance.new("Folder", Times)
	Stage6.Name = "Stage6"

	local Stage6BestTime = Instance.new("IntValue", Stage6)
	Stage6BestTime.Value = 0
	Stage6BestTime.Name = "BestTime"


	local Stage7 = Instance.new("Folder", Times)
	Stage7.Name = "Stage7"

	local Stage7BestTime = Instance.new("IntValue", Stage7)
	Stage7BestTime.Value = 0
	Stage7BestTime.Name = "BestTime"


	local StageHardmode = Instance.new("Folder", Times)
	Stage4.Name = "StageHardmode"

	local StageHardmodeBestTime = Instance.new("IntValue", StageHardmode)
	StageHardmodeBestTime.Value = 0
	StageHardmodeBestTime.Name = "BestTime"
	
	--Creating the trail inventory items.
	
	local Trails = Instance.new("Folder", player)
	Trails.Name = "Trails"
	
	local GreyTrail = Instance.new("IntValue", Trails)
	GreyTrail.Name = "GreyTrail"
	GreyTrail.Value = 0
	
	local RedTrail = Instance.new("IntValue", Trails)
	RedTrail.Name = "RedTrail"
	RedTrail.Value = 0
	
	local RainbowTrail = Instance.new("IntValue", Trails)
	RainbowTrail.Name = "RainbowTrail"
	RainbowTrail.Value = 0
	
	--Creating quest values.
	
	local Quests = Instance.new("Folder", player)
	Quests.Name = "Quests"
	
	local Speedrun = Instance.new("BoolValue", Quests)
	Speedrun.Name = "Speedrun"
	Speedrun.Value = false
	
	local BackpackItems = Instance.new("Folder", player)
	BackpackItems.Name = "BackpackItems"
	
	local SpeedCoil = Instance.new("IntValue", BackpackItems)
	SpeedCoil.Name = "SpeedCoil"
	SpeedCoil.Value = 0
	
	local stat = dataStore:GetAsync(player.UserId)
	
	if stat ~= nil then
		print("Player_"..player.UserId.." has data, successfully loaded data.")
		Coins.Value = stat[1]
		Level.Value = stat[2]
		Stage1BestTime.Value = stat[3]
		Stage2BestTime.Value = stat[4]
		Stage3BestTime.Value = stat[5]
		Stage4BestTime.Value = stat[6]
		RainbowTrail.Value = stat[7]
		RedTrail.Value = stat[8]
		GreyTrail.Value = stat[9]
		Speedrun.Value = stat[10]
		SpeedCoil.Value = stat[11]
		Stage5BestTime.Value = stat[12]
		Stage6BestTime.Value = stat[13]
		Stage7BestTime.Value = stat[14]
		StageHardmodeBestTime.Value = stat[15]
	else
		print("Player_"..player.UserId.." does not have any data.")
		Coins.Value = 0
		Level.Value = 1
		Stage1BestTime.Value = 0
		Stage2BestTime.Value = 0
		Stage3BestTime.Value = 0
		Stage4BestTime.Value = 0
		RainbowTrail.Value = 0
		RedTrail.Value = 0
		GreyTrail.Value = 0
		SpeedCoil.Value = 0
		Stage5BestTime.Value = 0
		Stage6BestTime.Value = 0
		Stage7BestTime.Value = 0
		StageHardmodeBestTime.Value = 0
	end
end)


game.Players.PlayerRemoving:Connect(function(player)
	local save = {}
	
	table.insert(save, player.leaderstats.Coins.Value)
	table.insert(save, player.leaderstats.Level.Value)
	table.insert(save, player.Times.Stage1.BestTime.Value)
	table.insert(save, player.Times.Stage2.BestTime.Value)
	table.insert(save, player.Times.Stage3.BestTime.Value) 
	table.insert(save, player.Times.Stage4.BestTime.Value)
	table.insert(save, player.Trails.RainbowTrail.Value)
	table.insert(save, player.Trails.RedTrail.Value)
	table.insert(save, player.Trails.GreyTrail.Value)
	table.insert(save, player.Quests.Speedrun.Value)
	table.insert(save, player.BackpackItems.SpeedCoil.Value)
	table.insert(save, player.Times.Stage5.BestTime.Value)
	table.insert(save, player.Times.Stage6.BestTime.Value)
	table.insert(save, player.Times.Stage7.BestTime.Value)
	table.insert(save, player.Times.StageHardmode.BestTime.Value)
	
	local success, errormessage = pcall(function()
		dataStore:SetAsync(player.UserId, save)
	end)
	
	if success then
		print("Saved: "..player.Name.."_"..player.UserId)
	end
end)

Also, whenever I look inside of the player model when playing, the Stage 4 folder is called Folder for some reason, so it’s not changing its name, still has the int value. Any help would be much appreciated :slight_smile:

image

found the impostor:

local StageHardmode = Instance.new("Folder", Times)
	Stage4.Name = "StageHardmode" <<<<<<<<<<<<< Stage4.Name, 

Correct was StageHardmode.Name
1 Like

Thank you so much, I’ve been trying to fix rthis for hours lmao

i know because that happened to me before xD

1 Like