What is going on with my Leaderstats?

NOTE: THIS HAPPENS 90% OF THE TIME, SOMETIMES IT ACTUALLY SHOWS THE REAL THING

It keeps doing this, even inside Roblox studio. I was just testing in-game and my leader stats GUI, and including my normal Leaderstats is that even if I get something to up my leader stats it does NOT change. How do I fix this? The GUI Is showing nothing. I don’t even have 600 dollars but it’s showing 600. I’m confused if yall need more information I can give it

Leaderstats Script

local Players = game:GetService(“Players”)
local RunService = game:GetService(“RunService”)
local DataStoreService = game:GetService(“DataStoreService”)
local Database = DataStoreService:GetDataStore(“Database”)

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

local Coins = Instance.new("IntValue")
Coins.Name = "Coins"
Coins.Parent = leaderstats

local Gems = Instance.new("IntValue")
Gems.Name = "Gems"
Gems.Parent = leaderstats

local Money = Instance.new("IntValue")
Money.Name = "Money"
Money.Parent = leaderstats

local EggsOpened = Instance.new("IntValue")
EggsOpened.Name = "EggsOpened"
EggsOpened.Parent = leaderstats

local success, data = pcall(function()
	return Database:GetAsync(player.UserId)
end)
if success and data then
	Coins.Value = data.Coins
	Gems.Value = data.Gems
	Money.Value = data.Money
	EggsOpened.Value = data.EggsOpened
elseif not success then
	warn("There was an error loading player data")
end

end)

Players.PlayerRemoving:Connect(function(player)
local newData = {
Coins = player.leaderstats.Coins.Value,
Gems = player.leaderstats.Gems.Value
}
local success, err = pcall(function()
Database:UpdateAsync(player.UserId, function(oldData)
return newData
end)
end)
if not success then
warn(err)
end
end)

game:BindToClose(function()
if RunService:IsStudio() then return end

for _, player in pairs(Players:GetPlayers()) do
	local newData = {
		Cash = player.leaderstats.Cash.Value,
		Gems = player.leaderstats.Gems.Value
	}
	local success, err = pcall(function()
		Database:UpdateAsync(player.UserId, function(oldData)
			return newData
		end)
	end)
	if not success then
		warn(err)
	end
end

end)

Leaderstat GUI Script

Coins = script.Parent.Parent.Parent.Parent.leaderstats.Coins

script.Parent.Text = " "…Coins.Value

Coins.Changed:connect(function()

script.Parent.Text = " "…Coins.Value

end)

image

What it says in output

Edit: It also sometimes does this In roblox studio

1 Like

We cant really help without some sort of access to some parts of the script

Do you need my leaderstats script? and my GUI stats script

You dont need to give all of it, you can just give the parts you think is the issue.

It doesnt give any error message. also how do I put the little script box thingy for devforum

Scripts dont always include errors, usually they see no issues but runs incorrectly. You can add the program box thingy by selecting the texts, and pressing the </> icon on the top of the textbox. Ag the moment I cannot really help at the moment now because I have to sleep

I rededited the page reload it

do you see anything wrong that could cause the problem?

Try getting the LocalPlayer and use WaitForChild() to wait for leader stats or something :man_shrugging:

When setting the text to the IntValues, you dont need to add

text.Text = “”…value.Value

you can just do

text.Text = value.Value

In the output, it seems like it was not able to find any of the Intvalues. Was it working at the time you took an image of the output?

I cant really find the main cause. But im gonna assume the issue is somewhere related to this and that not loading fast enough or something.