Level System Worked Perfectly Fine and Stopped Working All of a Sudden

Where is this script located?

Could you also tell me what this prints?

Code:

--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables
local LeaderstatsEvents = ReplicatedStorage.LeaderstatsEvents
local LevelUp = LeaderstatsEvents.LevelUp
local RankUp = LeaderstatsEvents.RankUp

--//Tables
local CodesInfo = {
	Code1 = "Coins25",
	Code2 = "Coins50",
	Code3 = "Gems5",
}

--//Functions
Players.PlayerAdded:connect(function(Player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = Player

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

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

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

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

	--Other--
	local Rank = Instance.new("StringValue")
	Rank.Name = "Rank"
	Rank.Parent = Player

	--Quests--
	local QuestStats = Instance.new("Folder")
	QuestStats.Name = "QuestStats"
	QuestStats.Parent = Player

	local QuestNum = Instance.new("IntValue")
	QuestNum.Name = "QuestNum"
	QuestNum.Value = 1
	QuestNum.Parent = Player

	local QuestInProgress = Instance.new("BoolValue")
	QuestInProgress.Name = "QuestInProgress"
	QuestInProgress.Parent = Player

	--Quest Stats--
	local TimePlayed = Instance.new("IntValue")
	TimePlayed.Name = "TimePlayed"
	TimePlayed.Value = 0
	TimePlayed.Parent = QuestStats

	--Codes--
	local Codes = Instance.new("Folder")
	Codes.Name = "Codes"
	Codes.Parent = Player

	for codeName, codeReward in CodesInfo do
		local newCode = Instance.new("BoolValue")
		newCode.Name = codeName
		newCode.Parent = Codes

		local newReward = Instance.new("BoolValue")
		newReward.Name = "Reward"
		newReward.Value = codeReward
		newReward.Parent = newCode
	end

	--Stats--
	local PlayerStats = Instance.new("Folder")
	PlayerStats.Name = "PlayerStats"
	PlayerStats.Parent = Player

	--Boosts--
	local Boosts = Instance.new("Folder")
	Boosts.Name = "Boosts"
	Boosts.Parent = Player

	local CoinsBoost = Instance.new("IntValue")
	CoinsBoost.Name = "CoinsBoost"
	CoinsBoost.Value = 0
	CoinsBoost.Parent = Boosts

	local GemBoosts = Instance.new("IntValue")
	GemBoosts.Name = "GemsBoost"
	GemBoosts.Value = 0
	GemBoosts.Parent = Boosts

	--Update Log and Tutorial--
	local Updates = Instance.new("Folder")
	Updates.Name = "Updates"
	Updates.Parent = Player

	local Tutorial = Instance.new("BoolValue")
	Tutorial.Name = "Tutorial"
	Tutorial.Value = true
	Tutorial.Parent = Updates

	local BETA = Instance.new("BoolValue")
	BETA.Name = "BETA"
	BETA.Parent = Updates

	--Client Events--	
	Level.Changed:Connect(function()
		LevelUp:FireClient(Player)
	end)

	Rank.Changed:Connect(function()
		RankUp:FireClient(Player)
	end)  

	--Level System--
	Exp.Changed:Connect(function(newExp)
		local RequiredExp = Level.Value * 100 + 100
		print(newExp)

		if newExp >= RequiredExp then
			print("Level up")
			Exp.Value -= RequiredExp
			Level.Value += 1
		end
	end)
end)

It’s located in server script service and it printed absolutely nothing.

I just converted it to a LocalScript and it now all of a sudden works. I don’t know if that’s the best solution but if it works, it works. Thank you guys for the help!

GetPropertyChangedSignal works perfectly fine when i use it.

part.GetPropertyChangedSignal("Transparency"):Connect(function)

Here you go, this should work as a server script.

--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables
local LeaderstatsEvents = ReplicatedStorage.LeaderstatsEvents
local LevelUp = LeaderstatsEvents.LevelUp
local RankUp = LeaderstatsEvents.RankUp

--//Tables
local CodesInfo = {
	Code1 = "Coins25",
	Code2 = "Coins50",
	Code3 = "Gems5",
}

local function SetupPlayer(Player)

  if Player:FindFirstChild("leaderstats") then return end -- If it already fired PlayerAdded, ignore

  local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = Player

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

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

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

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

	--Other--
	local Rank = Instance.new("StringValue")
	Rank.Name = "Rank"
	Rank.Parent = Player

	--Quests--
	local QuestStats = Instance.new("Folder")
	QuestStats.Name = "QuestStats"
	QuestStats.Parent = Player

	local QuestNum = Instance.new("IntValue")
	QuestNum.Name = "QuestNum"
	QuestNum.Value = 1
	QuestNum.Parent = Player

	local QuestInProgress = Instance.new("BoolValue")
	QuestInProgress.Name = "QuestInProgress"
	QuestInProgress.Parent = Player

	--Quest Stats--
	local TimePlayed = Instance.new("IntValue")
	TimePlayed.Name = "TimePlayed"
	TimePlayed.Value = 0
	TimePlayed.Parent = QuestStats

	--Codes--
	local Codes = Instance.new("Folder")
	Codes.Name = "Codes"
	Codes.Parent = Player

	for codeName, codeReward in CodesInfo do
		local newCode = Instance.new("BoolValue")
		newCode.Name = codeName
		newCode.Parent = Codes

		local newReward = Instance.new("BoolValue")
		newReward.Name = "Reward"
		newReward.Value = codeReward
		newReward.Parent = newCode
	end

	--Stats--
	local PlayerStats = Instance.new("Folder")
	PlayerStats.Name = "PlayerStats"
	PlayerStats.Parent = Player

	--Boosts--
	local Boosts = Instance.new("Folder")
	Boosts.Name = "Boosts"
	Boosts.Parent = Player

	local CoinsBoost = Instance.new("IntValue")
	CoinsBoost.Name = "CoinsBoost"
	CoinsBoost.Value = 0
	CoinsBoost.Parent = Boosts

	local GemBoosts = Instance.new("IntValue")
	GemBoosts.Name = "GemsBoost"
	GemBoosts.Value = 0
	GemBoosts.Parent = Boosts

	--Update Log and Tutorial--
	local Updates = Instance.new("Folder")
	Updates.Name = "Updates"
	Updates.Parent = Player

	local Tutorial = Instance.new("BoolValue")
	Tutorial.Name = "Tutorial"
	Tutorial.Value = true
	Tutorial.Parent = Updates

	local BETA = Instance.new("BoolValue")
	BETA.Name = "BETA"
	BETA.Parent = Updates

	--Client Events--	
	Level.Changed:Connect(function()
		LevelUp:FireClient(Player)
	end)

	Rank.Changed:Connect(function()
		RankUp:FireClient(Player)
	end)  

	--Level System--
	Exp.Changed:Connect(function(newExp)
		local RequiredExp = Level.Value * 100 + 100
		print(newExp)

		if newExp >= RequiredExp then
			print("Level up")
			Exp.Value -= RequiredExp
			Level.Value += 1
		end
	end)
end

--//Functions
Players.PlayerAdded:connect(function(Player)
	SetupPlayer(Player) -- Setup leaderstats
end)

for _, Player in pairs(Players:GetPlayers()) do
  SetupPlayer(Player) -- Setup early players
end

The changes I made relate to early players, which don’t fire the PlayerAdded event (1st player or first two players typically)

Already got it fixed, but thanks for the help.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.