My leveling up system won't work

where i can add and how i can change this script:

-- LEVELSYSTEM
local function onLOVEChanged(plr, EXP, LOVE)
		local reset = false
	if UserData.Stats.LOVE >= 100 then
		UserData.Stats.LOVE = 100
		reset = true
	end
end

LOVE.Changed:connect(function()
	onLOVEChanged(plr, EXP, LOVE)
end)

EXP.Changed:connect(function()
	if UserData.Stats.LOVE < 100 then
		if UserData.Stats.EXP >=  (10 + 25*UserData.Stats.LOVE)  then
		UserData.Stats.EXP = UserData.Stats.EXP - (10 + 25*UserData.Stats.LOVE)
		UserData.Stats.LOVE = UserData.Stats.LOVE + 1
		end
	end
end)
--LEVE SYSTEN END

so it will work and this script:

--variables
local DataStore2 = require(game:GetService("ServerScriptService").MainModule)
local mainkey = "dadad"
DataStore2.Combine(mainkey, "Stats","SOULS","ITEMS","FOOD","ARMOR")

-- data table
local function SetDataTable()
	local UserData = {
		Stats = {
			["EXP"] = 0,
			["GOLD"] = 0,
			["RESET"] = 0,
			["LOVE"] = 1
			},
		SOULS = {
			["BasicSoul"] = true,
			["Determination"] = false,
			["Integrity"] = false,
			["Justice"] = false,
			["Perseverance"] = false,
			["Kindness"] = false,
			["Bravery"] = false,
			["Patience"] = false
		},
		ITEMS = {
			["Stick"] = true,
			["REALKnife"] = false	
		},
		ARMOR = {
			["Bandage"] = true,
			["HeartLocket"] = false	
		},
		FOOD = {
			["MonsterCandy"] = 0,	
		},
	}
	return UserData
end

--main

game.Players.PlayerAdded:Connect(function(plr)
	local UserData = DataStore2(mainkey,plr):Get(SetDataTable())
	
	local gaster = Instance.new("Folder")
	gaster.Name = "TobyFox"
	local soulsfolder = Instance.new("Folder")
	soulsfolder.Name = "SOULS"
	local ITEMS = Instance.new("Folder")
	ITEMS.Name = "ITEMS"
	local ARMOR = Instance.new("Folder")
	ARMOR.Name = "ARMOR"
	local FOOD = Instance.new("Folder")
	FOOD.Name = "FOOD"
	
	--userStats
	local LOVE = Instance.new("IntValue")
	LOVE.Name = "LOVE"
	local GOLD = Instance.new("IntValue")
	GOLD.Name = "GOLD"
	local RESET = Instance.new("IntValue")
	RESET.Name = "RESET"
	local EXP = Instance.new("IntValue")
	EXP.Name = "EXP"
	
	--souls
	local BasicSoul = Instance.new("BoolValue")
	BasicSoul.Name = "BasicSoul"
	local Determination = Instance.new("BoolValue")
	Determination.Name = "Determination"
	local Justice = Instance.new("BoolValue")
	Justice.Name = "Justice"
	local Integrity = Instance.new("BoolValue")
	Integrity.Name = "Integrity"
	local Bravery = Instance.new("BoolValue")
	Bravery.Name = "Bravery"
	local Kindness = Instance.new("BoolValue")
	Kindness.Name = "Kindness"
	local Patience = Instance.new("BoolValue")
	Patience.Name = "Patience"
	local Perseverance = Instance.new("BoolValue")
	Perseverance.Name = "Perseverance"
	
	--items
	local Stick = Instance.new("BoolValue")
	Stick.Name = "Stick"
	local REALKnife = Instance.new("BoolValue")
	REALKnife.Name = "REALKnife"
	
	--Armor
	local Bandage = Instance.new("BoolValue")
	Bandage.Name = "Bandage"
	local HeartLocket = Instance.new("BoolValue")
	HeartLocket.Name = "HeartLocket"
	
	
	--Food
	local MonsterCandy = Instance.new("IntValue")
	MonsterCandy.Name = "MonsterCandy"
	
	--StoreInFolder
	local StatsData = DataStore2("Stats", plr)
	local SoulsData = DataStore2("SOULS", plr)
	local ItemsData = DataStore2("ITEMS",plr)
	local FoodData = DataStore2("FOOD", plr)
	local ArmorData = DataStore2("ARMOR", plr)
	
	--Stats data
	local function UpdateStats(UpdateValue) -- updates value to current data
		LOVE.Value = StatsData:Get(UpdateValue).LOVE
		EXP.Value = StatsData:Get(UpdateValue).EXP
		GOLD.Value = StatsData:Get(UpdateValue).GOLD
		RESET.Value = StatsData:Get(UpdateValue).RESET
	end
	
	--Soul data
	local function UpdateSouls(UpdateValue)
		BasicSoul.Value = SoulsData:Get(UpdateValue).BasicSoul
		Determination.Value = SoulsData:Get(UpdateValue).Determination
		Perseverance.Value = SoulsData:Get(UpdateValue).Perseverance
		Patience.Value = SoulsData:Get(UpdateValue).Patience
		Kindness.Value = SoulsData:Get(UpdateValue).Kindness
		Bravery.Value = SoulsData:Get(UpdateValue).Bravery
		Justice.Value = SoulsData:Get(UpdateValue).Justice
		Integrity.Value = SoulsData:Get(UpdateValue).Integrity
	end
	
	--update data
	UpdateStats(UserData.Stats)
	UpdateSouls(UserData.SOULS)
	
	StatsData:OnUpdate(UpdateStats)
	SoulsData:OnUpdate(UpdateSouls)
	
	--parent
	gaster.Parent = plr
	soulsfolder.Parent = plr
	
	--allinonestats
	--stats
	LOVE.Parent = gaster
	RESET.Parent = gaster
	EXP.Parent = gaster
	GOLD.Parent = gaster
	--Souls
	Determination.Parent = soulsfolder
	BasicSoul.Parent = soulsfolder
	Perseverance.Parent = soulsfolder
	Integrity.Parent = soulsfolder
	Justice.Parent = soulsfolder
	Kindness.Parent = soulsfolder
	Bravery.Parent = soulsfolder
	Patience.Parent = soulsfolder
	
end)
workspace.yesname.ClickDetector.MouseClick:Connect(function(PlayerWhoClicked)
	local UserData = DataStore2(mainkey,PlayerWhoClicked):Get(SetDataTable())
	local StatsData = DataStore2("Stats", PlayerWhoClicked)
	 UserData.Stats.EXP = UserData.Stats.EXP + 1
	StatsData:Set(UserData.Stats)
--LEVE SYSTEN END
end)

i tried some ways but some of them making this system to not work and some of them make when i click the part named “yesname” don’t even give me exp, please help me, thanks in advance :slight_smile:

1 Like

Where is LOVE set? Also, why do you set the reset value, it is never used. I need thr full code to be able to tell the full problem.

Most likely, you are updating a table, which will not replicate to the client.

i tried to put my first script inside the plr connected but it didn’t worked, but what do you mean by saying where the LOVE set?

the reset boolvalue i’ll use that in the future so i set it just to don’t forget to add a feature to it after

Where is LOVE defined? It does not seem to be defined in the code you provided.

LOVE is a IntValue, inside the playerconnected function

When you do UserData.LOVE, that references the table and not the actual int value. Do you update the int values to the table somewhere, or is that the problem?

if i’m trying to change the value not from the table (UserData.Stats.EXP) and from plr.Folder.Statname.Value , it won’t store in the datastore2 , btw im using datastore2 i forgot to mention. and also if i print LOVE it prints a value…

You have to update both the table and the actual intValue object itself. They are not the same thing. The table is created from your SetDataTable() function, and the actual object is created later. You have to change the table value when you update the int value and vice versa.

oh i think i understand now the problem, but i dunno how to make it work?

Try hooking up a .Changed to your int value. When the int value is changed, change the table and update your data store 2. Then, you only have to change the int value itself.

(Set Player.TobbyFox.LOVE, and connect a .Changed to it)

workspace.yesname.ClickDetector.MouseClick:Connect(function(PlayerWhoClicked)
	local UserData = DataStore2(mainkey,PlayerWhoClicked):Get(SetDataTable())
	local StatsData = DataStore2("Stats", PlayerWhoClicked)
	 UserData.Stats.EXP = UserData.Stats.EXP + 1
	StatsData:Set(UserData.Stats)
--LEVE SYSTEN start
local EXPP = UserData.Stats["EXP"]
local LOVEE = UserData.Stats["LOVE"]
local function onLOVEChanged(PlayerWhoClicked, EXPP, LOVEE)
		local reset = false
	if UserData.Stats.LOVE >= 100 then
		UserData.Stats.LOVE = 100
		reset = true
		StatsData:Set(UserData.Stats)
	end
end
EXPP.Changed:connect(function()
	if UserData.Stats.LOVE < 100 then
		if UserData.Stats.EXP >=  (10 + 25*UserData.Stats.LOVE)  then
		UserData.Stats.EXP = UserData.Stats.EXP - (10 + 25*UserData.Stats.LOVE)
		UserData.Stats.LOVE = UserData.Stats.LOVE + 1
		StatsData:Set(UserData.Stats)
		end
	end
end)
LOVEE.Changed:connect(function()
	onLOVEChanged(PlayerWhoClicked, EXPP, LOVEE)
end)
end)

i tried something like this, am i close?

You don’t want to connect the .changed in the click detector event. You could also just set both value if that’s easier for you. The point is: Both the int value and table value have to be updated.

so do i place the script inside playerconnected event?

That is where the .Changed would go, yes. Then, just change the int value and update the data store in the click detector bit.

ok i placed this inside the playerconnected event:

	--LEVE SYSTEN start
local function onLOVEChanged(plr, EXP, LOVE)
		local reset = false
	if UserData.Stats.LOVE >= 100 then
		UserData.Stats.LOVE = 100
		reset = true
		StatsData:Set(UserData.Stats)
	end
end
EXP.Changed:connect(function()
	if UserData.Stats.LOVE < 100 then
		if UserData.Stats.EXP >=  (10 + 25*UserData.Stats.LOVE)  then
		UserData.Stats.EXP = UserData.Stats.EXP - (10 + 25*UserData.Stats.LOVE)
		UserData.Stats.LOVE = UserData.Stats.LOVE + 1
		StatsData:Set(UserData.Stats)
		end
	end
end)
LOVE.Changed:connect(function()
	onLOVEChanged(plr, EXP, LOVE)
end)

and this outside the plr connected :

workspace.yesname.ClickDetector.MouseClick:Connect(function(PlayerWhoClicked)
	local UserData = DataStore2(mainkey,PlayerWhoClicked):Get(SetDataTable())
	local StatsData = DataStore2("Stats", PlayerWhoClicked)
	 UserData.Stats.EXP = UserData.Stats.EXP + 1
	StatsData:Set(UserData.Stats)
end)

what i did wrong now? or what i haven’t added yet for this to work?

ok something weird, if im ingame below the exp to level up then it does nothing
https://gyazo.com/53d1805e8ea4901958101b5bd2385ab9

but if i join the game with exp above to level up it does this
https://gyazo.com/431e0e01817b295f0a7d3c5f57ee8b56