Script not detecting if value is greater than another

Wait a second. “Experience.Value”? does it know what that is? try changing it to Player.PlrStats.Experience.Value
Same with ExperienceNeed.Value change it to Player.PlrStats.ExperienceNeed.Value

function NewLevel()
if Level.Value < BaseStats.MaxLevel then
print(Player.PlrStats.Experience.Value >= Player.PlrStats.ExperienceNeed.Value)
if Player.PlrStats.Experience.Value >= Player.PlrStats.ExperienceNeed.Value then
Level.Value += 1
print(“ok”)
ExperienceNeed.Value -= Player.PlrStats.ExperienceNeed.Value
end
end
end
Experience.Changed:Connect(NewLevel)

Yes it knows what it is, its its in a folder and it already specified it, i could show u the whole script but it would probably be too overwhelming

That is valuable information that could allow me or even someone else to give you the info you need to get it working

well, have fun ig

local datastore = game:GetService("DataStoreService")
local Gamedata = datastore:GetGlobalDataStore("PlrStats2")
local BaseStats = {

	Health = 300;
	Chakra = 10;
	
	Stamina = 10;
	
	Mode = 10;
	Defence = 0;
	Strenth = 0;
	Experience = 0;
	ExperienceNeed = 0;
	Level = 1;
	MaxLevel = 100,



}



function saveData(Player,plrStats)

	local DataToSave = {}


	print("Saving Data...")
	for i, data in pairs(plrStats:GetChildren()) do
		DataToSave[i] = data.Value
	end

	Gamedata:SetAsync(Player.UserId,DataToSave)
	print("Spiritual Data Saved.")



end

game.Players.PlayerAdded:Connect(function(Player)

	local plrStats = Instance.new("Folder",Player)
	plrStats.Name = "PlrStats"

	local Health = Instance.new("NumberValue",plrStats)
	Health.Name = "Health"
	Health.Value = BaseStats.Health

	local Stamina = Instance.new("NumberValue",plrStats)
	Stamina.Name = "Stamina"
	Stamina.Value = BaseStats.Stamina
	
	local MaxStamina = Instance.new("NumberValue",plrStats)
	MaxStamina.Name = "MaxStamina"
	MaxStamina.Value = BaseStats.Stamina
	
	
	local Chakra = Instance.new("NumberValue",plrStats)
	Chakra.Name = "Chakra"
	Chakra.Value = BaseStats.Chakra
	
	local MaxChakra = Instance.new("NumberValue",plrStats)
	MaxChakra.Name = "MaxChakra"
	MaxChakra.Value = BaseStats.Chakra
	
	local Mode = Instance.new("NumberValue",plrStats)
	Mode.Name = "Mode"
	Mode.Value = BaseStats.Mode
	
	local MaxMode = Instance.new("NumberValue",plrStats)
	MaxMode.Name = "MaxMode"
	MaxMode.Value = BaseStats.Mode


	local Defence = Instance.new("NumberValue",plrStats)
	Defence.Name = "Defence"
	Defence.Value = BaseStats.Defence

	
	local Strenth = Instance.new("NumberValue",plrStats)
	Strenth.Name = "Strenth"
	Strenth.Value = BaseStats.Strenth

	

	local Experience = Instance.new("NumberValue",plrStats)
	Experience.Name = "Experience"
	Experience.Value = BaseStats.Experience
	
	local Element1 = Instance.new("StringValue", plrStats)
	Element1.Name = "Element1"
	
	local Trait = Instance.new("StringValue", plrStats)
	Trait.Name = "Trait"
	
	local Shirt = Instance.new("StringValue", plrStats)
	Shirt.Name = "Shirt"
	Shirt.Value = "Shirt1"
	
	local Pants = Instance.new("StringValue", plrStats)
	Pants.Name = "Pants"
	Pants.Value = "Pants1"
	
	local Hair = Instance.new("StringValue", plrStats)
	Hair.Name = "Hair"
	Hair.Value = "Hair1"
	
	local HeadBand = Instance.new("StringValue", plrStats)
	HeadBand.Name = "HeadBand"
	HeadBand.Value = "StraitHeadBand"
	
	local TuckedIn = Instance.new("BoolValue", plrStats)
	TuckedIn.Name = "TuckedIn"
	TuckedIn.Value = true
	
	
	local ExperienceNeed = Instance.new("NumberValue",plrStats)
	ExperienceNeed.Name = "ExperienceNeed"
	ExperienceNeed.Value = BaseStats.ExperienceNeed
	
	local Level = Instance.new("NumberValue",plrStats)
	Level.Name = "Level"
	Level.Value = BaseStats.Level

	local Cash = Instance.new("NumberValue",plrStats)
	Cash.Name = "Cash"
	Cash.Value = BaseStats.Cash
	
	local NormalSlot1 = Instance.new("StringValue",plrStats)
	NormalSlot1.Name = "NormalSlot1"
	NormalSlot1.Value = "Y"

	local NormalSlot2 = Instance.new("StringValue",plrStats)
	NormalSlot2.Name = "NormalSlot2"
	NormalSlot2.Value = "U"

	local NormalSlot3 = Instance.new("StringValue",plrStats)
	NormalSlot3.Name = "NormalSlot3"
	NormalSlot3.Value = "G"

	local NormalSlot4 = Instance.new("StringValue",plrStats)
	NormalSlot4.Name = "NormalSlot4"
	NormalSlot4.Value = "H"

	local NormalSlot5 = Instance.new("StringValue",plrStats)
	NormalSlot5.Name = "NormalSlot5"
	NormalSlot5.Value = "J"

	local NormalSlot6 = Instance.new("StringValue",plrStats)
	NormalSlot6.Name = "NormalSlot6"
	NormalSlot6.Value = "V"

	local SpecialSlot1 = Instance.new("StringValue",plrStats)
	SpecialSlot1.Name = "SpecialSlot1"
	SpecialSlot1.Value = "C"

	local SpecialSlot2 = Instance.new("StringValue",plrStats)
	SpecialSlot2.Name = "SpecialSlot2"
	SpecialSlot2.Value = "Z"

	local WeaponSlot = Instance.new("StringValue",plrStats)
	WeaponSlot.Name = "WeaponSlot"
	WeaponSlot.Value = "1"

	local ThrowableSlot = Instance.new("StringValue",plrStats)
	ThrowableSlot.Name = "ThrowableSlot"
	ThrowableSlot.Value = "2"

	local ExtraSlot1 = Instance.new("StringValue",plrStats)
	ExtraSlot1.Name = "ExtraSlot1"
	ExtraSlot1.Value = "3"

	local ExtraSlot2 = Instance.new("StringValue",plrStats)
	ExtraSlot2.Name = "ExtraSlot2"
	ExtraSlot2.Value = "4"
	
	Player.CharacterAdded:Connect(function(Character)
		local Humanoid = Character:WaitForChild("Humanoid")
		Humanoid.MaxHealth = Health.Value
		Humanoid.Health = Health.Value
	end)
	
	
	while wait() do
		local extraLevel = Level.Value
		local xpNeed = ((extraLevel * 2)-1) * 100
		if Player.PlrStats.Experience.Value > Player.PlrStats.ExperienceNeed.Value then
			print("ok")
		end
		ExperienceNeed.Value = xpNeed
		if Level.Value < BaseStats.MaxLevel then
			print(Player.PlrStats.Experience.Value >= Player.PlrStats.ExperienceNeed.Value)
			if Player.PlrStats.Experience.Value >= Player.PlrStats.ExperienceNeed.Value then
				Level.Value += 1
				print("ok")
				Experience.Value -= ExperienceNeed.Value
			end
		end
		
		
	end
	
	local plrsaves
		pcall (function()
			plrsaves = Gamedata:GetAsync(Player.UserId)
			
		end)
	if plrsaves then
		--If player has data
		warn("Player has Stat Data!")
		for i, data in pairs(plrStats:GetDescendants()) do

			data.Value = plrsaves[i]

			print (data.Name,":",data.Value)
		end

	else

		--if player doenst have data
		warn("Player has no Stat Data.")
		for i, data in pairs(plrStats:GetChildren()) do

			print (data.Name,":",data.Value)

		end	
	end
	


end)



game.Players.PlayerRemoving:Connect(function(Player)
	local PlrStats = Player:WaitForChild("PlrStats")
	saveData(Player,PlrStats)

end)

uh? “Strenth”???

Have you tried the :heart: button?

1 Like

I have no idea what you mean, but does it have to do with what we are trying to solve?

No but it is spelt wrong if you didn’t notice

Oh well, i can fix that later, doesnt rlly matter right now

I got an idea. something that could blow this WIDE open.
Edit: It prints both values and prints a warning if it’s smaller

local datastore = game:GetService("DataStoreService")
local Gamedata = datastore:GetGlobalDataStore("PlrStats2")
local BaseStats = {

	Health = 300;
	Chakra = 10;
	
	Stamina = 10;
	
	Mode = 10;
	Defence = 0;
	Strenth = 0;
	Experience = 0;
	ExperienceNeed = 0;
	Level = 1;
	MaxLevel = 100,



}



function saveData(Player,plrStats)

	local DataToSave = {}


	print("Saving Data...")
	for i, data in pairs(plrStats:GetChildren()) do
		DataToSave[i] = data.Value
	end

	Gamedata:SetAsync(Player.UserId,DataToSave)
	print("Spiritual Data Saved.")



end

game.Players.PlayerAdded:Connect(function(Player)

	local plrStats = Instance.new("Folder",Player)
	plrStats.Name = "PlrStats"

	local Health = Instance.new("NumberValue",plrStats)
	Health.Name = "Health"
	Health.Value = BaseStats.Health

	local Stamina = Instance.new("NumberValue",plrStats)
	Stamina.Name = "Stamina"
	Stamina.Value = BaseStats.Stamina
	
	local MaxStamina = Instance.new("NumberValue",plrStats)
	MaxStamina.Name = "MaxStamina"
	MaxStamina.Value = BaseStats.Stamina
	
	
	local Chakra = Instance.new("NumberValue",plrStats)
	Chakra.Name = "Chakra"
	Chakra.Value = BaseStats.Chakra
	
	local MaxChakra = Instance.new("NumberValue",plrStats)
	MaxChakra.Name = "MaxChakra"
	MaxChakra.Value = BaseStats.Chakra
	
	local Mode = Instance.new("NumberValue",plrStats)
	Mode.Name = "Mode"
	Mode.Value = BaseStats.Mode
	
	local MaxMode = Instance.new("NumberValue",plrStats)
	MaxMode.Name = "MaxMode"
	MaxMode.Value = BaseStats.Mode


	local Defence = Instance.new("NumberValue",plrStats)
	Defence.Name = "Defence"
	Defence.Value = BaseStats.Defence

	
	local Strenth = Instance.new("NumberValue",plrStats)
	Strenth.Name = "Strenth"
	Strenth.Value = BaseStats.Strenth

	

	local Experience = Instance.new("NumberValue",plrStats)
	Experience.Name = "Experience"
	Experience.Value = BaseStats.Experience
	
	local Element1 = Instance.new("StringValue", plrStats)
	Element1.Name = "Element1"
	
	local Trait = Instance.new("StringValue", plrStats)
	Trait.Name = "Trait"
	
	local Shirt = Instance.new("StringValue", plrStats)
	Shirt.Name = "Shirt"
	Shirt.Value = "Shirt1"
	
	local Pants = Instance.new("StringValue", plrStats)
	Pants.Name = "Pants"
	Pants.Value = "Pants1"
	
	local Hair = Instance.new("StringValue", plrStats)
	Hair.Name = "Hair"
	Hair.Value = "Hair1"
	
	local HeadBand = Instance.new("StringValue", plrStats)
	HeadBand.Name = "HeadBand"
	HeadBand.Value = "StraitHeadBand"
	
	local TuckedIn = Instance.new("BoolValue", plrStats)
	TuckedIn.Name = "TuckedIn"
	TuckedIn.Value = true
	
	
	local ExperienceNeed = Instance.new("NumberValue",plrStats)
	ExperienceNeed.Name = "ExperienceNeed"
	ExperienceNeed.Value = BaseStats.ExperienceNeed
	
	local Level = Instance.new("NumberValue",plrStats)
	Level.Name = "Level"
	Level.Value = BaseStats.Level

	local Cash = Instance.new("NumberValue",plrStats)
	Cash.Name = "Cash"
	Cash.Value = BaseStats.Cash
	
	local NormalSlot1 = Instance.new("StringValue",plrStats)
	NormalSlot1.Name = "NormalSlot1"
	NormalSlot1.Value = "Y"

	local NormalSlot2 = Instance.new("StringValue",plrStats)
	NormalSlot2.Name = "NormalSlot2"
	NormalSlot2.Value = "U"

	local NormalSlot3 = Instance.new("StringValue",plrStats)
	NormalSlot3.Name = "NormalSlot3"
	NormalSlot3.Value = "G"

	local NormalSlot4 = Instance.new("StringValue",plrStats)
	NormalSlot4.Name = "NormalSlot4"
	NormalSlot4.Value = "H"

	local NormalSlot5 = Instance.new("StringValue",plrStats)
	NormalSlot5.Name = "NormalSlot5"
	NormalSlot5.Value = "J"

	local NormalSlot6 = Instance.new("StringValue",plrStats)
	NormalSlot6.Name = "NormalSlot6"
	NormalSlot6.Value = "V"

	local SpecialSlot1 = Instance.new("StringValue",plrStats)
	SpecialSlot1.Name = "SpecialSlot1"
	SpecialSlot1.Value = "C"

	local SpecialSlot2 = Instance.new("StringValue",plrStats)
	SpecialSlot2.Name = "SpecialSlot2"
	SpecialSlot2.Value = "Z"

	local WeaponSlot = Instance.new("StringValue",plrStats)
	WeaponSlot.Name = "WeaponSlot"
	WeaponSlot.Value = "1"

	local ThrowableSlot = Instance.new("StringValue",plrStats)
	ThrowableSlot.Name = "ThrowableSlot"
	ThrowableSlot.Value = "2"

	local ExtraSlot1 = Instance.new("StringValue",plrStats)
	ExtraSlot1.Name = "ExtraSlot1"
	ExtraSlot1.Value = "3"

	local ExtraSlot2 = Instance.new("StringValue",plrStats)
	ExtraSlot2.Name = "ExtraSlot2"
	ExtraSlot2.Value = "4"
	
	Player.CharacterAdded:Connect(function(Character)
		local Humanoid = Character:WaitForChild("Humanoid")
		Humanoid.MaxHealth = Health.Value
		Humanoid.Health = Health.Value
	end)
	
	
	while wait() do
		local extraLevel = Level.Value
		local xpNeed = ((extraLevel * 2)-1) * 100
		if Player.PlrStats.Experience.Value > Player.PlrStats.ExperienceNeed.Value then
			print("ok")
		end
		ExperienceNeed.Value = xpNeed
		if Level.Value < BaseStats.MaxLevel then
			print(Player.PlrStats.Experience.Value)
			print(Player.PlrStats.ExperienceNeed.Value)
			print(Player.PlrStats.Experience.Value >= Player.PlrStats.ExperienceNeed.Value)
			if Player.PlrStats.Experience.Value >= Player.PlrStats.ExperienceNeed.Value then
				Level.Value += 1
				print("ok")
				Experience.Value -= ExperienceNeed.Value
			end
		else
			warn("Not bigger")
		end
		
		
	end
	
	local plrsaves
		pcall (function()
			plrsaves = Gamedata:GetAsync(Player.UserId)
			
		end)
	if plrsaves then
		--If player has data
		warn("Player has Stat Data!")
		for i, data in pairs(plrStats:GetDescendants()) do

			data.Value = plrsaves[i]

			print (data.Name,":",data.Value)
		end

	else

		--if player doenst have data
		warn("Player has no Stat Data.")
		for i, data in pairs(plrStats:GetChildren()) do

			print (data.Name,":",data.Value)

		end	
	end
	


end)



game.Players.PlayerRemoving:Connect(function(Player)
	local PlrStats = Player:WaitForChild("PlrStats")
	saveData(Player,PlrStats)

end)

Yeah so, nun of the values update, but it makes no sense?

Hey so, im actually really disappointed in myself. SO basically, i had to change the value from a server script so it was changed server sided. The sad thing is that i new this the entire time and refused to do it, but i finally did it and now it works. Im very sorry for my laziness and wasting your time :sob:

Oh well. It brings me joy to finally be able to help people. :smiley:
I forgive you.

1 Like

Make sure to mark one of these as the Solution:

That’s odd after setting all this up and creating a data store save found the loop didn’t work at all.

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