My leaderstats script is broken

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? My leaderstats script is BROKEN

  2. What is the issue? It was working fine until randomly it stopped. No errors. Character added is not working.

game.Players.PlayerAdded:Connect(function(Player)
	print("added")
	local data = game:GetService('DataStoreService')
	local saveData = data:GetDataStore('saveData',Player.UserId)
	local gold = saveData:getAsync('gold')
	local level = saveData:getAsync('level')
	
	local xp = saveData:getAsync('xp')
	print("data")
	
	local stats = Instance.new("Folder",Player)
	stats.Name = "leaderstats"
	
	local Gold = Instance.new("IntValue",stats)
	Gold.Value = gold or 0
	Gold.Name = "Gold"
	print("Gold")
	
	local Level = Instance.new("IntValue",Player.leaderstats)
	Level.Value = level or 1
	
	Level.Name = "Level"
	
	
	print("Level")
	
	
	Player.CharacterAdded:Connect(function(Character) -- Works up to here
		print("char") -- does not print
		
		
		
		local Xp = Instance.new("IntValue",Character)
	Xp.Value = xp or 0
		Xp.Name = "XP"
		print("loaded")
		
	
		local TeamColor = Instance.new("BrickColorValue",Character)
		TeamColor.Name = "TeamColor"
		
		local TeamColor3 = Instance.new("Color3Value",Character)
		TeamColor3.Name = "TeamColor3"
		
		local TypeOfRace = Instance.new("StringValue",Character)
		TypeOfRace.Name = "CurrentRace"
		
		
		local LastAttacker = Instance.new("ObjectValue",Character)
		LastAttacker.Name = "LastAttacker"
		
		local CurrentAttackMode = Instance.new("StringValue",Character)
		CurrentAttackMode.Name = "CurrentAttackMode"
		CurrentAttackMode.Value = "Primary"
		
		
		
		while true do
			task.wait(.75)
			if TeamColor.Value == "Really Red" then
				TeamColor3.Value = Color3.fromRGB(255, 0, 0)
			elseif TeamColor.Value == "Really Blue" then
				TeamColor3.Value = Color3.fromRGB(0, 0, 255)
				
			end
			Character.Humanoid.Died:Connect(function(Die)
				if LastAttacker.Value ~= "" then
					
					game.Players:GetPlayerFromCharacter(LastAttacker.Value).PlayerGui.Ui.MoneyGainLabel.Activated.Value = true

					game.Players:GetPlayerFromCharacter(LastAttacker.Value).PlayerGui.Ui.MoneyGainLabel.GainMoneyValue.Value = math.random(1,10)
					
					
			
			end
			end)
			
			TeamColor.Value = game.Players:GetPlayerFromCharacter(Character).TeamColor
			local HPbillboard = game.ServerStorage.HPBillboardGui:Clone()
			HPbillboard.Parent = Character.Head
			HPbillboard.StudsOffset = Vector3.new(0,3,0)
			local healthScript = Character:WaitForChild("Health")
			healthScript:Destroy()
			while true do
				task.wait(.1)
				
				HPbillboard.TextLabel.Text = "Health "..Character.Humanoid.Health.."/"..Character.Humanoid.MaxHealth
			end
			
		
			
			
		end
	end)
end)

Is there any errors in the script?

This issue has been answered already.

1 Like

Does this only happen in studio?

1 Like