Leaderstats is there but the intvalue is not there?!

so i checked the player, there IS a leaderstats folder.
but no “Wins” IntValue inside the folder?

local DSS = game:GetService("DataStoreService")
local WinsDataStore = DSS:GetDataStore("Wins")
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(plr)
	local ls = Instance.new("Folder")
	ls.Name = "leaderstats"
	ls.Parent = plr
	
	local Wins = Instance.new("IntValue")
	Wins.Name = "Wins"
	Wins.Value = WinsDataStore:GetAsync(plr.UserId) or 0
	Wins.Parent = ls
end)

Players.PlayerRemoving:Connect(function(plr)
	WinsDataStore:SetAsync(plr.UserId, plr.leaderstats.Wins.Value)
end)

game:BindToClose(function()
	for i, plr in pairs(Players:GetPlayers()) do
		WinsDataStore:SetAsync(plr.UserId, plr.leaderstats.Wins.Value)
	end
end)

so the problem is NOT about the datastore, the problem is about the intvalue itself, it is not even appearing on the leaderstats. :neutral_face:

1 Like

There could be an error if the WinsDataStore isn’t able to get the players data. Consider wrapping it in a pcall().

1 Like

Hmm. Have you checked console for errors? (F9, or type /console in chat while testing)

no!

the problem is not about the datastore…
i should make that text bigger…

but… the problem is that the value ITSELF is not even showing up on the leaderstats

ok, i am going to inculde pcall function at the instance.new(“IntValue”) instead,

there is no errror about itself…

502: API Services rejected request with error. Error code: 30 Reason: The provided universe is not valid.

the output.

.:neutral_face: :neutral_face: :neutral_face:

Considering you seem to be getting an API error, have you enabled Studio access to API services?

Also is your game published, think that may be causing it to error.

it ssays failed to load.
so i decided to enable Studio access to API serviceson the website instead, so i enabled it.

If that doesn’t work, have you tried reloading Studio?

The error is indeed about the data store. The script breaks before the parent of IntValue is assigned.

I fixed your script for you :slight_smile:

local Players = game:GetService("Players")
local TestService = game:GetService("TestService")
local RunService = game:GetService("RunService")
local DSS = game:GetService("DataStoreService")
local WinsDataStore = DataStoreService:GetDataStore("Wins") --Name the DataStore whatever you want

Players.PlayerAdded:Connect(function(plr)

    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = plr


	local Wins = Instance.new("IntValue")
	Wins.Name = "Wins"
    Wins.Parent = leaderstats
	Wins.Value = 0

	local value1Data = Wins

	local s, e = pcall(function()
		value1Data = WinsDataStore:GetAsync(plr.UserId..'-Value1') or 0 --check if they have data, if not it'll be "0"
	end)

	if s then
		Wins.Value = value1Data --setting data if its success
	else
		TestService:Error(e)  --if not success then we error it to the console
	end
end)

Players.PlayerRemoving:Connect(function(plr)
local s, e = pcall(function()
	   WinsDataStore:SetAsync(plr.UserId..'-Value1', plr.leaderstats.Wins.Value) --setting data
	end)
	   if not s then TestService:Error(e) 
	end
end)

game:BindToClose(function(plr)
      if not RunService:IsStudio() then
          local s, e = pcall(function()
	      WinsDataStore:SetAsync(plr.UserId..'-Value1', plr.leaderstats.Wins.Value) --setting data
	end)
	    if not s then TestService:Error(e) 
	end

    end)
end)

thanks but…
the problem is not about the data store itself.
it is about the int values itself, the intvalues does not even create

Have you tried the script I made yet?

1 Like

IT WORKED BUT…

why my script is not wroking???

literally Instance.new, this first letter is a capital letter and the other are lowercases

Instnace

and then
new, all lowercases.

and a dot between them

Instance.new

why should not my script work?

this is how inside the player looks like ( without including starterplayerscripts, etc.):
lshowlooklike

VS

How it SHOULD Look like:

lshowshouldlooklike

I have literally no idea but it is working now?
how?
I don’t know how…
well at least it IS working.