Is this bug or my code wrong?

Hello! Im trying to use instance to create folder but when I run sometime the folder is create and sometimes it won’t create or show up.


When it work.
Screen Shot 2564-10-20 at 14.27.10
When it won’t work.
Screen Shot 2564-10-20 at 14.27.24

Note: I use the same code.
Thank for helping. :grin:

What are the properties of your script?

you mean server script or local? it server

No, with properties I mean if it’s disabled or if archivable is on

achievable is on and it not disable

Then I don’t know what is wrong, the script looks fine to me. Do you sometimes get any errors inside the output? If there could be an error with the code above it would completely stop the script from working

Can you show us your function (DataStore2) it might be possible, that this function infinitely yields.

Maybe show the full script? Would be helpful!

when it won’t work all code in player added event didn’t work as I try to print

local DataStore2 = require(1936396537)

local StartLevel = 1
local StartExp = 0

DataStore2.Combine("DATA", "level", "exp")


game:GetService("Players").PlayerAdded:Connect(function(player)
	
	local LevelStore = DataStore2("level", player)
	local ExpStore = DataStore2("exp", player)
	
	local statsFolder = Instance.new("Folder", player)
	statsFolder.Name = "Stats"
	 print("GG")
	
	local Level = Instance.new("IntValue", statsFolder)
	Level.Name = "Level"
	
	
	local Exp = Instance.new("IntValue", statsFolder)
	Exp.Name = "Exp"
	
	local function LevelUpdate(value)
		print("Level Updated")
		Level.Value = LevelStore:Get(value)
	end
	
	local function ExpUpdate(value)
		print("Exp Updated")
		Exp.Value = ExpStore:Get(value)
	end
	
	LevelUpdate(StartLevel)
	ExpUpdate(StartExp)
	
	LevelStore:OnUpdate(LevelUpdate)
	ExpStore:OnUpdate(function()
		ExpUpdate(StartExp)
		
		local neededExp = 50

		if Exp.Value >= neededExp then
			ExpStore:Increment(-neededExp)
			LevelStore:Increment(1)
		end
		
	end)
end)

i ran it twice and it only worked once.

You should try to printing something before you create the Folder (Line 5 in your screenshot).

Sometime it work but sometime it not.

You should try to read what I said, tell us the results of it!



I ran this 2 times

You should try to connect the PlayerAdded event before you do stuff with the DataStore, the problem might be, that the player joins before the DataStoreRequest has been processed. Try to move “DataStore2.Combine(…)” behind the “PlayerAdded” event.

u mean move down under playeradded event or inside

Move it down, BEHIND the “PlayerAdded” event. Inside of it doesn’t make any sense.

after I try to run for a several time it won’t work sometimes

Can you send me the whole script? Not just the screenshot.



local DataStore2 = require(1936396537)

local StartLevel = 1
local StartExp = 0

print("before add")



game:GetService("Players").PlayerAdded:Connect(function(player)
	game.Workspace.Part.BrickColor = BrickColor.new("Really blue")
	print("PlayerAdded")
	local LevelStore = DataStore2("level", player)
	local ExpStore = DataStore2("exp", player)
	
	local statsFolder = Instance.new("Folder", player)
	statsFolder.Name = "Stats"
	 print("After create stats")
	
	local Level = Instance.new("IntValue", statsFolder)
	Level.Name = "Level"
	
	
	local Exp = Instance.new("IntValue", statsFolder)
	Exp.Name = "Exp"
	
	local function LevelUpdate(value)
		print("Level Updated")
		Level.Value = LevelStore:Get(value)
	end
	
	local function ExpUpdate(value)
		print("Exp Updated")
		Exp.Value = ExpStore:Get(value)
	end
	
	LevelUpdate(StartLevel)
	ExpUpdate(StartExp)
	
	LevelStore:OnUpdate(LevelUpdate)
	ExpStore:OnUpdate(function()
		ExpUpdate(StartExp)
		
		local neededExp = 50

		if Exp.Value >= neededExp then
			ExpStore:Increment(-neededExp)
			LevelStore:Increment(1)
		end
		
	end)
end)

DataStore2.Combine("DATA", "level", "exp")

game.Workspace.Part.ClickDetector.MouseClick:Connect(function(player)
	local LevelStore = DataStore2("level", player)
	local ExpStore = DataStore2("exp", player)
	ExpStore:Increment(1000) 
end)