I have a problem in my game with leaderstats Value

Hello, I’m trying to fix my machine in my game but I tried something and that show me an error, if anyone can help or feedback as soon as possible that will be helpful.
I need a help I did a leaderstats and the leaderstats Value Not equal to the datastorage NumberValue into the Playerdata Folder so I’m trying to do the leaderstats Value equal to the Datastorage Numbervalue
if anyone can Help me that will be amazing! image

1 Like

Can we see the script so we can see what’s wrong please?

could you send picture of the script? so we check the mistake

I also tried to do the other Thing

and the result:


There is no error but my Points Value is still 0

and my datastorage Points is else

This is the result of the Leaderstats:
image

I’m trying to do The Datastorage Points value equal to the leaderstats Value

im send you my game leaderstats script give me 1 sec to open it

but wait Look what I sent I edited my message

the player data should be on the serverstorage, and the script on the serverscript service

but I did the playerdata into replicatedstorage and this is working well With the Cash function

the problem only with the leaderstats not with the datastorage Function The datastorage Function working well

I think the problem is that you’ve been in a for loop of players when you have the player right in front of you in the PlayersAdded function. Your parameter is the player, so I think you shouldn’t loop through players.

Maybe try this.

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

   local points = Instance.new("NumberValue")
   points.Name = "Points"
   points.Parent = player
   points.Value = game.Players.PlayerData[player.Name].Points.Value
end)
1 Like

This is not working but I think if you have any way to fix it That will be awesome

I think that’s is more easily this:

game.Players.PlayerAdded:Connect(function(player)
	local Folder = Instance.new("Folder")
	Folder.Parent = player
	Folder.Name = "leaderstats"
	
    local  Points = instance.new("IntValue")
    points.Name = "Points"
    points.Parent = Folder
end)

if you want to save the player’s data just put this script:

local DataStore = game:GetService("DataStoreService")
local MyData = DataStore:GetDataStore("leaderstats")

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

	local Points = Instance.new("IntValue")
	Points.Name = "Points"
	Points.Parent = Folder
	Points.Value = MyData:GetAsync("stat1-"..player.UserId)
end)

game.Players.PlayerRemoving:Connect(function(player)
	local Data1 = player.leaderstats.Points.Value
	MyData:SetAsync("stat1-"..player.UserId, Data1)
end)

oh but What is Dato1 I tried to do it but There is no name who called Dato1

Oh yeah I saw the error Now Is working Prove It. please give me a like!!

oh but wait who this is Cloned 2 times the same leaderstats folder

Oh! other thing If you want to save the player’s data you have to activate The API Service

so all I have to do that use only with the other thing?

local MyData = DataStore:GetDataStore("leaderstats")

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

	local Points = Instance.new("IntValue")
	Points.Name = "Points"
	Points.Parent = Folder
	Points.Value = MyData:GetAsync("stat1-"..player.UserId)
end)

game.Players.PlayerRemoving:Connect(function(player)
	local Data1 = player.leaderstats.Points.Value
	MyData:SetAsync("stat1-"..player.UserId, Data1)
end)

Maybe you have other script Search in your workspace

Oh! I think that I know what is happening you have to copy only this script:

local DataStore = game:GetService("DataStoreService")
local MyData = DataStore:GetDataStore("leaderstats")

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

	local Points = Instance.new("IntValue")
	Points.Name = "Points"
	Points.Parent = Folder
	Points.Value = MyData:GetAsync("stat1-"..player.UserId)
end)

game.Players.PlayerRemoving:Connect(function(player)
	local Data1 = player.leaderstats.Points.Value
	MyData:SetAsync("stat1-"..player.UserId, Data1)
end)