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

Why is my folder leaderstats is not showing at my player when I run the game?

local currencyName = "Credits"

local killName = "Kills"

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



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


	
	local currency = Instance.new("IntValue")
	currency.Name = currencyName
	currency.Parent = folder
	
	local kill = Instance.new("IntValue")
	kill.Name = killName
	kill.Parent = folder
	
	local ID = currencyName.."-"..player.UserId
	local ID = killName.."-"..player.UserId
	local savedData = nil
	
	pcall(function()
		savedData = DataStore:GetAsync (ID)
	end)
	
	if savedData ~= nil then
		currency.Value = savedData
		kill.Value = savedData
		print("Data loaded")
	else 
		currency.Value = 1000
		kill.Value = 0
		print("New player to the game")
	end
	
		
end)

this is my whole script but the script I'm having trouble is this one.


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

I'm sure this is correct. But why does it not show? I use a normal script in serverscriptservice. There is no other script that block this.

10 comments

0

Try printing the name of folder after you make it. It could be you are looking in the wrong place for leaderstats. 

0

Also you don’t have to say ~= nil. You can just say the variable. If the variable isn’t nil it will do what’s in the if statement. Just saves time lol

0

I tried searching the leaderstats folder in my explorer. But it doesn't exist like my problem script don't work.

0

print(folder.Name) and see if it prints leaderstats.

0

Or say if player:FindFirstChild(“leaderstats”) then print(“hi”) end If leaderstats is in player it will print hi.  Are you getting an error in output?

0

not working I decided to make another file and try to use the script. It works! So I just need to copy all my files to a new game.

0

That’s odd. If it still doesn’t work check the output. It could be a script causing it to crash.

0

eromusics it seems to me that you aren't showing the full script. on line 44 I see an extra end. Is there any part of the script that is a yielding function? ex: WaitForChild().

0

oh didnt click read extra comments xD sorry

0

By the way there is no errors about the script in the output. If there is any errors I should already know what is the problem. I suspect an item or script is making my script not working at somepoint.

2 answers

The answer is that an item or a script is making the script not working. I try to leave the file for a few minutes and it doesn't work again. So I make a conclusion is that I need to find the script and remove it.

2 comments

0

Nevermind... still not working. I do think the script is at fault here. I leave a new game file with ONLY that script. works for the first time. Leave it a couple of minute. Try open it again and it's not working

0

I finally find out that the local datastore is the cause. I don't exactly know why but when I delete that line it works.

Your script is correct, this also happens to me. Can you change one of your Int-Values and check if shows?

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