You created a level on the leaderboard, but no values are displayed. What's the problem

You created a level on the leaderboard, but no values are displayed. What’s the problem


game.Players.PlayerAdded:Connect(function(player) --게임속에 플레이어가 접속하면 함수 실행
	
	local ls = Instance.new("Folder",player)
	ls.Name = "leaderstats"
	
	
	local Money = Instance.new("NumberValue",ls)
	Money.Value = 0
	Money.Name = "Money"
	
	local Kill = Instance.new("NumberValue",ls)
	Kill.Value = 0
	Kill.Name = "Kill"
	
	local Death = Instance.new("NumberValue",ls)
	Death.Value = 0
	Death.Name = "Death"
	
	local Level = Instance.new("StringValue",ls)
	Level.Value = "SILVER"
	Level.Name = "Level"
	
	local score = player.leaderstats.Kill.Value - player.leaderstats.Death.Value

	if  score < 0 then
		player.leaderstats.Level.Value = "BRONZE"

	elseif score > 49 and score <= 199 then
		player.leaderstats.Level.Value = "GOLD"
	elseif score >=200 and score <=399 then
		player.leaderstats.Level.Value = "DIAMOND"
	elseif score >=400 and score <=799 then
		player.leaderstats.Level.Value = "MASTER"	
	elseif score >=800 then
		player.leaderstats.Level.Value = "CHALLENGER"		

	end

제목 없음

add this:
if score.Value == 0 than
level.Value = “silver”
end

1 Like

Another script may be affecting the leaderstat, because I’ve tried the same exact script you posted here in studio and it worked completly fine. Feel free to post any other scripts you think may be doing this!

1 Like

The error of disappearing values has been resolved
Thank you.
But even if I kill, my level is fixed to silver

The error of disappearing values has been resolved
Thank you.
But even if I kill, my level is fixed to silver

local datastore =game:GetService("DataStoreService") :GetDataStore("PlayerStats") --데이터 저장 장소 지정해주기
local Player = game:GetService("Players")
local kill = game.ReplicatedStorage.kill
local death = game.ReplicatedStorage.death




game.Players.PlayerAdded:Connect(function(player) --게임속에 플레이어가 접속하면 함수 실행
	
	local ls = Instance.new("Folder",player)
	ls.Name = "leaderstats"
	
	
	local Money = Instance.new("NumberValue",ls)
	Money.Value = 0
	Money.Name = "Money"
	
	local Kill = Instance.new("NumberValue",ls)
	Kill.Value = 0
	Kill.Name = "Kill"
	
	local Death = Instance.new("NumberValue",ls)
	Death.Value = 0
	Death.Name = "Death"
	
	local Level = Instance.new("StringValue",ls)
	Level.Value = "SILVER"
	Level.Name = "Level"
	
	local score = player.leaderstats.Kill.Value - player.leaderstats.Death.Value
	if  score < 0 then
		player.leaderstats.Level.Value = "BRONZE"

	elseif score > 49 and score <= 199 then
		player.leaderstats.Level.Value = "GOLD"
	elseif score >=200 and score <=399 then
		player.leaderstats.Level.Value = "DIAMOND"
	elseif score >=400 and score <=799 then
		player.leaderstats.Level.Value = "MASTER"	
	elseif score >=800 then
		player.leaderstats.Level.Value = "CHALLENGER"		

	end

	player.CharacterAdded:Connect(function(char)
	
		
		char.Humanoid.Died:connect(function()
			
			local creator = char.Humanoid:FindFirstChild("creator")
			if creator then
				local killplr = creator.Value --죽인플레이어 확인
				local DeathPlayer = Player:GetPlayerFromCharacter(creator.Parent.Parent)
				if killplr then
					killplr.leaderstats.Kill.Value += 1
					killplr.leaderstats.Money.Value += 10
					
					kill:FireClient(killplr) --죽인사람 10달러 획득이미지
					
			
					DeathPlayer.leaderstats.Death.Value += 1
					DeathPlayer.leaderstats.Money.Value -= 5
					
						death:FireClient(DeathPlayer) ----죽은사람 마이너스 오달라
					
				

					
				end
			end
		end)
	end)
	
	local ownsSportcar = Instance.new("BoolValue", player)
	ownsSportcar.Name  = "ownsSportcar"
	ownsSportcar.Value = false
	

	
	game.ReplicatedStorage.RemoteEvent2.OnServerEvent:Connect(function()
		if player.leaderstats.Money.Value >= 10 then
			player.leaderstats.Money.Value -= 10
			player.ownsSportcar.Value = true
			
		end
		
	end)
	
	local MoneyData --데이터 불러오기

	local KillData
	local DeathData
	local LevelData
	
	--에러방지 
	local success, errormessage = pcall(function()       
		MoneyData = datastore:GetAsync(player.UserId.."-Money")
		KillData = datastore:GetAsync(player.UserId.."-Kill")
		DeathData = datastore:GetAsync(player.UserId.."-Death")
		LevelData = datastore:GetAsync(player.UserId.."-Level")
		
		
	end)
	if success then
		Money.Value = MoneyData
		Kill.Value = KillData
		Death.Value = DeathData
		Level.Value = LevelData
	
	else
		warn(errormessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)     
	datastore:SetAsync(player.UserId.."-Money",player.leaderstats.Money.Value)
	datastore:SetAsync(player.UserId.."-Kill",player.leaderstats.Kill.Value)
	datastore:SetAsync(player.UserId.."-Death",player.leaderstats.Death.Value)
	datastore:SetAsync(player.UserId.."-Level",player.leaderstats.Level.Value)

end)

you need to add this:

level.Changed:Connect(Function()
       if  score < 0 then
		player.leaderstats.Level.Value = "BRONZE"

	elseif score > 49 and score <= 199 then
		player.leaderstats.Level.Value = "GOLD"
	elseif score >=200 and score <=399 then
		player.leaderstats.Level.Value = "DIAMOND"
	elseif score >=400 and score <=799 then
		player.leaderstats.Level.Value = "MASTER"	
	elseif score >=800 then
		player.leaderstats.Level.Value = "CHALLENGER"
end)
1 Like

I entered it, but it’s fixed in silver… Why is that

When you kill nothing happens because you’re only actually changing the levels when the player joins the game. You need to make it so eveytime the Death leaderstat changes or the Kill leaderstat changes the script checks if the levels can also be changed!

function ApplyLevel(player) -- Function for updating the levels of the player argument
	local score = player.leaderstats.Kill.Value - player.leaderstats.Death.Value

	if  score < 0 then
		player.leaderstats.Level.Value = "BRONZE"

	elseif score > 49 and score <= 199 then
		player.leaderstats.Level.Value = "GOLD"
	elseif score >=200 and score <=399 then
		player.leaderstats.Level.Value = "DIAMOND"
	elseif score >=400 and score <=799 then
		player.leaderstats.Level.Value = "MASTER"	
	elseif score >=800 then
		player.leaderstats.Level.Value = "CHALLENGER"
	end
end

game.Players.PlayerAdded:Connect(function(player) --게임속에 플레이어가 접속하면 함수 실행

	local ls = Instance.new("Folder",player)
	ls.Name = "leaderstats"

	local Money = Instance.new("NumberValue")
	Money.Parent = ls
	Money.Value = 0
	Money.Name = "Money"

	local Kill = Instance.new("NumberValue")
	Kill.Parent = ls
	Kill.Value = 0
	Kill.Name = "Kill"

	local Death = Instance.new("NumberValue")
	Death.Parent = ls
	Death.Value = 0
	Death.Name = "Death"

	local Level = Instance.new("StringValue")
	Level.Parent = ls
	Level.Value = "SILVER"
	Level.Name = "Level"

	ApplyLevel(player) -- Apply the levels at the start of the game
	
	Kill:GetPropertyChangedSignal("Value"):Connect(function()
		ApplyLevel(player) -- When the value of Kill changes, apply levels again
	end)
	Death:GetPropertyChangedSignal("Value"):Connect(function()
		ApplyLevel(player) -- When the value of Death changes, apply levels again
	end)
	
end)
1 Like

does the score change when you kill?

I’ve made some modifications and this works perfectly. Thank you so much

1 Like

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