I need help with this script

  1. What do you want to achieve?
    I want to achieve a leaderstats that saves and shows on the uis

  2. What is the issue?
    The leaderstats wont work on the uis even in the leaderstats script it has the values and still it wont show

  3. What solutions have you tried so far?
    I checked the uis scripts and there wasnt anything wrong.

local DataStoreService = game:GetService("DataStoreService")
local DataStore1 = DataStoreService:GetDataStore("DataStore1")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder",player)
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local Coins = Instance.new("NumberValue", leaderstats)
	Coins.Name = "Coins"
	Coins.Parent = leaderstats
	Coins.Value = 0
	
	local DJumps = Instance.new("NumberValue",player)
	DJumps.Name = "DJumps"
	
	local MaxJumps = Instance.new("NumberValue",DJumps)
	MaxJumps.Name = "MaxDJumps"
	MaxJumps.Value = 1
	
	local Boost = Instance.new("NumberValue",DJumps)
	Boost.Name = "Boost"
	Boost.Value = MaxJumps.Value
	
	local Need = Instance.new("NumberValue",DJumps)
	Need.Name = 'Need'
	Need.Value = 100
	
	local Strength = Instance.new("NumberValue", leaderstats)
	Strength.Name = "Strength"
	Strength.Parent = leaderstats
	Strength.Value = 0
	
	local Capacity = Instance.new("NumberValue")
	Capacity.Name = "Capacity"
	Capacity.Parent = leaderstats
	Capacity.Value = 10
	
	local Diamonds = Instance.new("NumberValue", leaderstats)
	Diamonds.Name = "Diamonds"
	Diamonds.Parent = leaderstats
	Diamonds.Value = 0
	
	local Rank = Instance.new("IntValue", leaderstats)
	Rank.Name = "Rank"
	Rank.Parent = leaderstats
	Rank.Value = "MiniFlyWeight"
	
	local key = player.UserId

	local data
	local success,msg = pcall(function()
		data = DataStore1:GetAsync(key)
	end)

	if success then
		print("Data Loaded")
		Strength.Value = data.S
		Capacity.Value = data.C
		Rank.Value = data.R
		Diamonds.Value = data.D
		Coins.Value = data.Cs
		MaxJumps.Value = data.M
		Need.Value = data.N
	else
		print("Error")
		warn(msg)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local key = player.UserId

	local data = {
		C = player.leaderstats.Capacity.Value,
		Cs = player.leaderstats.Coins.Value,
		S = player.leaderstats.Strength.Value,
		D = player.leaderstats.Diamonds.Value,
		R = player.leaderstats.Rank.Value,
		M = player.DJumps.MaxDJumps.Value,
		N = player.DJumps.Need.Value,
	}

	local success,msg = pcall(function()
		DataStore1:SetAsync(key,data)
	end)

	if success then
		print("Data Saved!")
	end
end)

Please dont write the entire script
Thank you

1 Like

If the leaderstat script has the values then the issue lies with how its drawn not the data

1 Like

I still dont really know what the solution is

We would need to see how the leaderboard creates its frames and whatnot.

1 Like

its is not a leaderboard it is a leaderstats the leaderstats for some reason make the values = 0

1 Like

Give the UIS script just to double check

1 Like
local player = game.Players.LocalPlayer
local s = require(game.ReplicatedStorage:WaitForChild("ModuleScript"))
while wait() do
	script.Parent.Text = s.Shorter(player.leaderstats.Strength.Value).." / "..s.Shorter(player.leaderstats.Capacity.Value)
end

Whats the module script? Also you should be using changed event on the strength value not a while loop.

1 Like
local Number = {}

Number.Shorter = function(IN)
	
	if IN < 1e6 and IN >= 1e3 then
		IN = (IN/1e3).."K"
		
	elseif IN < 1e9 and IN >= 1e6 then
		IN = (IN/1e6).."M"
	elseif IN < 1e12 and IN >= 1e9 then
		IN = (IN/1e9).."B"
	elseif IN < 1e15 and IN >= 1e12 then
		IN = (IN/1e12).."t"
	elseif IN < 1e18 and IN >= 1e15 then
		IN = (IN/1e15).."q"
	elseif IN < 1e21 and IN >= 1e18 then
		IN = (IN/1e18).."Q"
	elseif IN < 1e24 and IN >= 1e21 then
		IN = (IN/1e21).."s"
	elseif IN < 1e27 and IN >= 1e624 then
		IN = (IN/1e24).."S"
	elseif IN < 1e30 and IN >= 1e27 then
		IN = (IN/1e27).."o"
	elseif IN < 1e33 and IN >= 1e30 then
		IN = (IN/1e30).."d"
	elseif IN < 1e36 and IN >= 1e33 then
		IN = (IN/133).."U"
	elseif IN < 1e39 and IN >= 1e36 then
		IN = (IN/1e36).."D"
	elseif IN < 1e42 and IN >= 1e39 then
		IN = (IN/1e39).."T"
	elseif IN < 1e45 and IN >= 1e42 then
		IN = (IN/1e42).."Qd"
	elseif IN < 1e48 and IN >= 1e45 then
		IN = (IN/1e45).."Qc"
	elseif IN < 1e51 and IN >= 1e48 then
		IN = (IN/1e48).."Sd"
	elseif IN < 1e54 and IN >= 1e51 then
		IN = (IN/1e51).."St"
	elseif IN < 1e57 and IN >= 1e54 then
		IN = (IN/1e54).."O"
	elseif IN < 1e60 and IN >= 1e57 then
		IN = (IN/1e57).."N"
	elseif IN < 1e63 and IN >= 1e60 then
		IN = (IN/1e60).."V"
	end
	return IN
end

return Number

Ok so, I have had a play around with this code, and I changed this part:

if success then
	print("Data Loaded")
	Strength.Value = data.S
	Capacity.Value = data.C
	Rank.Value = data.R
	Diamonds.Value = data.D
	Coins.Value = data.Cs
	MaxJumps.Value = data.M
	Need.Value = data.N
else
	print("Error")
	warn(msg)
end

to

if data then
	print("Data Loaded")
	Strength.Value = data.S
	Capacity.Value = data.C
	Rank.Value = data.R
	Diamonds.Value = data.D
	Coins.Value = data.Cs
	MaxJumps.Value = data.M
	Need.Value = data.N
else
	print("Error")
	warn(msg)
end

so it checks to see if there is any data there instead of checking if the pcall is true or false. I am not sure why, but it was reading as true, so the script was erroing when it was trying to change the leaderstats values with no data in it. For this to work, I also was not able to use the studio gameplay, only the actual game.

Thank you for the help still the values = 0

For which part of the game is the value still 0?

It is the capacity value on the leaderstats script the capacity value is 10 when you play the game the value is set to 0

image

On the leaderboard like in the picture shown? Mine comes out as 10 like it should.

When i play my capacity value is 0

You could have the datastore value already set to 0 from when you were previously testing it.

image

is there anyway it could be fixed?

Do you have a datastore editor? If not, the one I use is: DataStore Editor - Roblox it is 150 robux though, however you can probably find another one somewhere. You can get something like this and edit your datastores in studio.

could you send the leaderstats script you fixed