Coins not showing with gui

Then position the function above the things that need to use updateLevel

so i should remove the one at the bottom and keep the one on top?

Select the updateLevel at the bottom and do Ctrl + x to cut it, select the one at the top and do ctrl + v

It works but it broke the leaderstats on here


Screen Shot 2021-03-07 at 12.37.03 PM

Show the code again please, there’s probazbly something wrong

local replicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")

local DataStore2 = require(ServerStorage:WaitForChild("DataStore2"))

DataStore2.Combine("Data", "Inventory", "Currency", "Level", "Exp")

local defaultLevel = 1
local defaultexp = 0
local DefaultCurrencyAmount = 0
local DefaultHealthAmount = 150

local expToLevelUp = function(level)
	return 100 + level * 15
end

game.Players.PlayerAdded:Connect(function(player)
	
	--All the DataStores in here--
	local InventoryStore = DataStore2("Inventory", player)
	local CurrencyStore = DataStore2("Currency", player)
	local ExpStore = DataStore2("Exp", player)
	local LevelStore = DataStore2("Level", player)
	local replicatedDataFolder = Instance.new("Folder")
	replicatedDataFolder.Parent = replicatedStorage.ReplicatedData
	replicatedDataFolder.Name = player.UserId
	
	
	---------------------------------------------
		--STARTING THE INVENTORY FUNCTION--
	local inventoryString = Instance.new("StringValue")
	inventoryString.Parent = replicatedDataFolder
	inventoryString.Name = "Inventory"
	
	--Leaderstats--
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local LevelValue = Instance.new("IntValue", leaderstats)
	LevelValue.Name = "Level"
	
	local expValue = Instance.new("IntValue", leaderstats)
	expValue.Name = "Exp"
	----------------------------------------------
	
	
				--Functions--
	local function updateLevel(amount)
		replicatedStorage.Events.UpdateClientLevel:FireClient(player, amount)
		print("Good")
	end
	
	local function updateEXP(exp)
		if exp >= expToLevelUp(LevelStore:Get(defaultLevel)) then
			ExpStore:Increment(expToLevelUp(LevelStore:Get(defaultLevel)) * -1)
			LevelStore:Increment(1)
		else
			player.leaderstats.Exp.Value = exp
		end
	end

	local inventoryData = InventoryStore:Get({})
	inventoryString.Value = HttpService:JSONEncode(inventoryData)
	
	InventoryStore:OnUpdate(function(decodedData)
		inventoryString.Value = HttpService:JSONEncode(decodedData)
	end)
	
	local function updateClientCurrency(amount)
		replicatedStorage.Events.UpdateClientCurrency:FireClient(player, amount)
	end

	updateClientCurrency(CurrencyStore:Get(DefaultCurrencyAmount))

	CurrencyStore:OnUpdate(updateClientCurrency)
	--call functions right away one time
	updateLevel(LevelStore:Get(defaultLevel))
	updateEXP(ExpStore:Get(defaultexp))

end)

game.Workspace:WaitForChild("Bruh").ClickDetector.MouseClick:Connect(function(player)
	
	local CurrencyStore = DataStore2("Currency", player)
	
	CurrencyStore:Increment(1,DefaultCurrencyAmount)
end)

Where are the OnUpdates for updateLevel and updateExp? You removed them

I re-added it and now the exp is working now but the level is still 0?

Did you add the OnUpdate for updateexp too

This is what i did

updateLevel(LevelStore:Get(defaultLevel))
	updateEXP(ExpStore:Get(defaultexp))
	
	LevelStore:OnUpdate(updateLevel)
	ExpStore:OnUpdate(updateEXP)

end)

Dude, I meant for you to add this back at the bottom

LevelStore:OnUpdate(updateLevel)
ExpStore:OnUpdate(updateEXP)

yeah i added it on the bottom

This is getting confusing, send the code again

local replicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")

local DataStore2 = require(ServerStorage:WaitForChild("DataStore2"))

DataStore2.Combine("Data", "Inventory", "Currency", "Level", "Exp")

local defaultLevel = 1
local defaultexp = 0
local DefaultCurrencyAmount = 0
local DefaultHealthAmount = 150

local expToLevelUp = function(level)
	return 100 + level * 15
end

game.Players.PlayerAdded:Connect(function(player)
	
	--All the DataStores in here--
	local InventoryStore = DataStore2("Inventory", player)
	local CurrencyStore = DataStore2("Currency", player)
	local ExpStore = DataStore2("Exp", player)
	local LevelStore = DataStore2("Level", player)
	local replicatedDataFolder = Instance.new("Folder")
	replicatedDataFolder.Parent = replicatedStorage.ReplicatedData
	replicatedDataFolder.Name = player.UserId
	
	
	---------------------------------------------
		--STARTING THE INVENTORY FUNCTION--
	local inventoryString = Instance.new("StringValue")
	inventoryString.Parent = replicatedDataFolder
	inventoryString.Name = "Inventory"
	
	--Leaderstats--
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local LevelValue = Instance.new("IntValue", leaderstats)
	LevelValue.Name = "Level"
	
	local expValue = Instance.new("IntValue", leaderstats)
	expValue.Name = "Exp"
	----------------------------------------------
	
	
	--Functions--
	
	local function updateLevel(amount)
		replicatedStorage.Events.UpdateClientLevel:FireClient(player, amount)
		print("Good")
	end
	
	local function updateEXP(exp)
		if exp >= expToLevelUp(LevelStore:Get(defaultLevel)) then
			ExpStore:Increment(expToLevelUp(LevelStore:Get(defaultLevel)) * -1)
			LevelStore:Increment(1)
		else
			player.leaderstats.Exp.Value = exp
		end
	end

	local inventoryData = InventoryStore:Get({})
	inventoryString.Value = HttpService:JSONEncode(inventoryData)
	
	InventoryStore:OnUpdate(function(decodedData)
		inventoryString.Value = HttpService:JSONEncode(decodedData)
	end)
	
	local function updateClientCurrency(amount)
		replicatedStorage.Events.UpdateClientCurrency:FireClient(player, amount)
	end

	updateClientCurrency(CurrencyStore:Get(DefaultCurrencyAmount))

	CurrencyStore:OnUpdate(updateClientCurrency)
	--call functions right away one time
	updateLevel(LevelStore:Get(defaultLevel))
	updateEXP(ExpStore:Get(defaultexp))
	
	LevelStore:OnUpdate(updateLevel)
	ExpStore:OnUpdate(updateEXP)

end)

game.Workspace:WaitForChild("Bruh").ClickDetector.MouseClick:Connect(function(player)
	
	local CurrencyStore = DataStore2("Currency", player)
	
	CurrencyStore:Increment(1,DefaultCurrencyAmount)
end)

Im not sure what it could be, what happens when you try to run it right now?

Replace that with this

local function updateLevel(amount)
	plr.leaderstats.Level.Value = amount
	replicatedStorage.Events.UpdateClientLevel:FireClient(player, amount)
	print("Good")
end

It says Attempt nil with leader stats

My bad, it should be player not plr, I use the latter a lot so I confused myself

Thanks it works now :smiley:

2 Likes