How would I Give a Player in game a tool when they reach a certain Number on the leaderboard [UNSLOVED]

I need to give a tool to The Player But when I test it does basically nothing I’ve tried search the Dev Forum for a while now and have came back empty Handed
here is The code that does not work

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
	local leaderstats = player.leaderstats.level
		
		local e = leaderstats
		if e.Value  == 2 then
			player.Backpack.Sword:Destroy()
			local sword = game.Lighting["non-gamepass-swordS"].Baton:Clone()
			sword.Parent = player.Backpack
		end
			if e.Value == 7 then
			player.Backpack.Batom:Destory()
			local sword = game.Lighting["non-gamepass-swordS"].Icesword:Clone()
			sword.Parent = player.Backpack
		end
			if e.Value == 15 then
				player.Backpack.Sword:Destroy()
				player.Backpack.Batom:Destory()
			player.Backpack.Icesword:Destory()
			local sword = game.Lighting["non-gamepass-swordS"]["Spirit Sword"]:Clone()
			sword.Parent = player.Backpack
		end
			if e.Value == 25 then
				
			player.Backpack["Spirit Sword"]:Destory()
			local sword = game.Lighting["non-gamepass-swordS"]["Blood Sword"]:Clone()
			sword.Parent = player.Backpack
		end
			if e.Value == 34 then
			player.Backpack["Blood Sword"]:Destory()
			local sword = game.Lighting["non-gamepass-swordS"]["Crimson Sword"]:Clone()
			sword.Parent = player.Backpack
		end
			if e.Value == 50 then	
			player.Backpack["Crimson Sword"]:Destory()
			local sword = game.Lighting["non-gamepass-swordS"]["Purple sword"]:Clone()
			sword.Parent = player.Backpack
		end
			if e.Value == 70 then
			player.Backpack["Purple sword"]:Destory()
			local sword = game.Lighting["non-gamepass-swordS"][Power sword"]:Clone()
			sword.Parent = player.Backpack
		end
	end)
end)

When do you want this script to fire? At the moment, it only fires when the player’s character is added.

well its because when the player dies the player looses its tools so i basically added that in so the player does not loose the the sword when the player dies

Alright, that makes sense then. I’m not sure if the two functions will work. Maybe consider changing it to

game.Workspace.ChildAdded:Connect(function(child)
print(child) -- Check if the child is humanoid then get the player's name
end)

my goal here is to give a tool to the player that has that certain level to get to said tool i’ll try that i guess though

That’s no worries.

game.Workspace.ChildAdded:Connect(function(child)
local player = game.Players:FindFirstChild(child.Name) 
if player then
-- Code
end)

The first thing I see is an error message on line 5. It can’t find what ‘level’ is.

Maybe because leaderstats folders Are not located in Workspace for crying out loud they are located in Game.Players when the player joins the game

Is it located in the player or game.Players?

its located in game.players when the player joins the game like this
image it is inside that player right there

Can you send a screenshot of the leaderstats please?

image
its legit the same thing you see on leaderboards in game

Perhaps try

local leaderstats = player.leaderstats:WaitForChild("level")

I legit just told you It is not located within Workspace its located within Players when they join in game.players

I understand, and the script isn’t looking for it in the workspace. The script just can’t find “levels” in the player’s folder.

game.Workspace.ChildAdded:Connect(function(child) -- We use this to first find the player. 

Try to make it
If e.value >2
Instead of = ؟

1 Like
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = player.leaderstats.level 
leaderstats.Value = 50
end)

This is how you modify a leaderstats value when a player joins the Game
please stop making this more complex than it has to be

i’ll try that that sounds more promissing

This will only fire when a player joins the game, it cannot fire if a player resets their character or dies.