Does it print both prints from the function and RemoteEvent?
oh it works, but it only works when someone levels up
Does both of them print? Or does one print and the other doesn’t?
how do i make it so it shows everytime
both of them printed
What do you mean by this statement?
So before someone levels up, it shows this
Because i put that originally but when the i level up it shows the level im at
Isn’t the fact that it shows the level you’re at showing it’s working though?
its working, but it only shows when im leveled up
What only shows when you’re levelled up? I’m not understanding
So at first you start off with the gui saying Dude Level? that’s odd, you already stated that you want to call them right away one time, may I have a look at your current code again
which code the datahandler?
Yes, that script is what I need to see
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(level)
player.leaderstats.Level.Value = level
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))
--call function right away one time
local function updateLevel(amount)
replicatedStorage.Events.UpdateClientLevel:FireClient(player, amount)
print("Good")
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)
I see your issue, I told you to remove this:
local function updateLevel(level)
player.leaderstats.Level.Value = level
end
But you kept it, the reason it doesn’t work the first time is because the first time call calls the wrong function
Put
local function updateLevel(amount)
replicatedStorage.Events.UpdateClientLevel:FireClient(player, amount)
print("Good")
end
above
updateLevel(LevelStore:Get(defaultLevel))
updateEXP(ExpStore:Get(defaultexp))
So it looks like this
local function updateLevel(amount)
replicatedStorage.Events.UpdateClientLevel:FireClient(player, amount)
print("Good")
end
updateLevel(LevelStore:Get(defaultLevel))
updateEXP(ExpStore:Get(defaultexp))
Oh i was looking at the wrong function sorry
then what do i do with this function at the bottom?
local function updateLevel(amount)
replicatedStorage.Events.UpdateClientLevel:FireClient(player, amount)
print("Good")
end
updateLevel(LevelStore:Get(defaultLevel))
updateEXP(ExpStore:Get(defaultexp))
[/quote]
You keep that one and remove the one at the top
but when i do that every word that has updateLevel says unknown global updateLevel