alr i did but it doesn’t work?
Even after you have the right amount of exp?
yes, my level rn is at 1 but it doesn’t show
Try changing it to
script.Parent.Text = "Level: " .. tostring(amount)
oof still does nothing
Show your Data Handler code as it is right now
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 expToLeveUp = function(level)
return 100 + level * 5
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(level)
player.leaderstats.Level.Value = level
end
local function updateEXP(exp)
if exp >= expToLeveUp(LevelStore:Get(defaultLevel)) then
ExpStore:Increment(expToLeveUp(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(defaultexp))
updateEXP(ExpStore:Get(defaultexp))
--call function right away one time
local function updateLevel(level)
replicatedStorage.Events.UpdateClientLevel:FireClient(player,level)
end
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)
Try removing this and try again, it could be that this is overwriting the one you made at the end
it doesn’t work
i think it was the same problem from before
I don’t think it can be that since the OnUpdates are not inside another one, try putting a print inside of the updateLevel function to see if it prints anything
So when i level up it prints but it doesn’t update the text
local function updateLevel(level)
print("Good")
player.leaderstats.Level.Value = level
end
LevelStore:OnUpdate(updateLevel)
ExpStore:OnUpdate(updateEXP)
You’re using the wrong function, that’s why it’s not working, the function should do like updateCurrency, call the RemoteEvent, in your case, instead of setting the value of Level to be the current level, call the updateClientLevel event
can you show me what you mean?
This function works because it’s calling UpdateClientCurrency, the function you have to update the level doesn’t do that, your updatelevel function should look like this
local function updateLevel(amount)
replicatedStorage.Events.UpdateClientLevel:FireClient(player, amount)
end
This will work, the former you had didn’t cause it never called the event that changed the level
I tried that but, it never did anything?
It never did anything, didn’t you say the code for the UpdateClientLevel was
replicatedStorage.Events.UpdateClientLevel.OnClientEvent:Connect(function(amount)
script.Parent.Text = "Level: " .. tostring(amount)
end)
Did you make the RemoteEvent and palce it in the Events folder? Are there any errors showing up? Is it in the textlabel for the level?
Yes, i made a remote event called UpdateClientEvent and in the Events folder, no errors are showing up
In your current updateLevel function which should be like I wrote it, put a print in there and put a print in the OnClientEvent code for UpdateClientLevel
it prints when i level up