Needing help on make a leaderstats folder

Hello, I’m trying to make a game where whenever you swing a sword, you gain skill, and the skill goes onto a leaderstats leaderboard. However, I get output errors whenever I try to make one, saying that I tried to index nil with the variable. I asked this on a different post before but the user I03v (JellyM015) decided to copy and paste my code and told me to try it out and didnt even have anything to do with leaderstats. Here’s my code:

Sword Code

task.wait(1.5)

local Character
local Player
local SkillPoints

local ScriptsFolder = script.Parent
local Tool = ScriptsFolder.Parent
local AnimationsFolder = Tool:WaitForChild("Animations")

local epicSwingAnimation = AnimationsFolder:WaitForChild("epicSwordSwing")
local epicSwingTrack

local Cooldown = false
local CooldownWait = 0.75

Tool.Equipped:Connect(function()
	Character = Tool.Parent
	Player = game:GetService("Players"):GetPlayerFromCharacter(Character)
	SkillPoints = Player:WaitForChild("PlayerSkill") -- Wait for PlayerSkill to be available

	local humanoid = Character:FindFirstChild("Humanoid")

	if humanoid then
		epicSwingTrack = humanoid:LoadAnimation(epicSwingAnimation)
	end
end)


Tool.Activated:Connect(function()
	if Cooldown == false then
		Cooldown = true

		SkillPoints.Value += 5
		print("You earned 5 skill, and now have", SkillPoints.Value, "Skill Points!")
		epicSwingTrack:Play()

		wait(CooldownWait)
		Cooldown = false
	end
end)

Skill System Code

local players = game:GetService("Players")
local dataStores = game:GetService("DataStoreService")
local playerSkillDataStore = dataStores:GetDataStore("PlayerSkill")

players.PlayerAdded:Connect(function(plr)
	
	PlayerSkill = Instance.new('IntValue')
	PlayerSkill.Name = "PlayerSkill"
	PlayerSkill.Parent = plr
	
	task.wait(1)
	
	PlayerSkill.Value = 0
	
	local SkillData = playerSkillDataStore:GetAsync(plr.UserId)
	
	if SkillData then
		print("Player has data")
		PlayerSkill.Value = SkillData
		if PlayerSkill.Value >= 1 then
			print("You already have some skill, let's get some more!")
			
		else
			print("You don't have any skill, so let's get some!")
			
		end
	
	else
		print("Player has no data... womp womp")
		playerSkillDataStore:SetAsync(plr.UserId, 0)
		print("Player now has data... yipee!!!")
		print("It's time to start gaining skill!")
		while true do 
			task.wait(1)
			PlayerSkill.Value += 1
			print(PlayerSkill.Value)
		end
	end
end)

players.PlayerRemoving:Connect(function(plr)
	local PlayerSkill = plr:WaitForChild("PlayerSkill")
	playerSkillDataStore:SetAsync(plr.UserId, PlayerSkill.Value)
end)

If you are the user I mentioned above please don’t waste my time again

1 Like

May you post the errors, please.

1 Like

okay gimme a sec to open studio again

well the only error was this

-- Attempt to index nil with SkillPoints

the question im asking is how can i make a leaderstats folder for all this
the last guy wasn’t too bright so he just posted my code in a reply

So it shows up on the player list?

what do you mean by that sorry im kinda new to studio i dont know many vocab words that you guys use

so you want it to look like this?
image

yes please i want somethin like that

however the skill points system is in an entirely different script

make a folder and name the folder to “leaderstats”

i know how to make standard leaderstats im just wondering how can i transfer the variable SkillPoints into the other script that handles leaderstats (sorry if this wasnt in desc)

do this:

local players = game:GetService("Players")
local dataStores = game:GetService("DataStoreService")
local playerSkillDataStore = dataStores:GetDataStore("PlayerSkill")

players.PlayerAdded:Connect(function(plr)
	leaderstats = Instance.new("Folder", plr)
        leaderstats.Name =  "leaderstats"

	PlayerSkill = Instance.new('IntValue')
	PlayerSkill.Name = "PlayerSkill"
	PlayerSkill.Parent = leaderstats
	
	task.wait(1)
	
	PlayerSkill.Value = 0
	
	local SkillData = playerSkillDataStore:GetAsync(plr.UserId)
	
	if SkillData then
		print("Player has data")
		PlayerSkill.Value = SkillData
		if PlayerSkill.Value >= 1 then
			print("You already have some skill, let's get some more!")
			
		else
			print("You don't have any skill, so let's get some!")
			
		end
	
	else
		print("Player has no data... womp womp")
		playerSkillDataStore:SetAsync(plr.UserId, 0)
		print("Player now has data... yipee!!!")
		print("It's time to start gaining skill!")
		while true do 
			task.wait(1)
			PlayerSkill.Value += 1
			print(PlayerSkill.Value)
		end
	end
end)

players.PlayerRemoving:Connect(function(plr)
	local PlayerSkill = plr:WaitForChild("PlayerSkill")
	playerSkillDataStore:SetAsync(plr.UserId, PlayerSkill.Value)
end)
1 Like

cuz theres 1 script that handles the skill points themselves and the datastores but the leaderstats are in an entirely different folder

okay

ill try this out

hope it works

you would need to create a variable to access the folder

though if what I am thinking is what you want the script I sent to you should work.

AW MAN!!!

PlayerSkill is not a valid member of Player “Players.Pish85”

Players.Pish85.Backpack.Sword.Scripts.Script:35: attempt to index nil with ‘Value’

i hate the output

however the actual leaderboard works though :slight_smile:

alright good, happy to have helped