Value error....pls help!

hi , my Melee and my defend keep Setting to zero,


game.Players.PlayerAdded:Connect(function(player)
	if ServerStorage:FindFirstChild(".playerproperty") then
		local PlayerProperty = ServerStorage:WaitForChild(".playerproperty")
		local Folder = Instance.new("Folder")
		Folder.Name = player.Name
		Folder.Parent = PlayerProperty
		local Stats  = Instance.new("Folder")
		Stats.Name = "Stats"
		Stats.Parent = Folder
		local Melee =Instance.new("IntValue")
		Melee.Name = "Melee"
		Melee.Parent = Stats
		local Stamina = Instance.new("IntValue")
		Stamina.Name  = "Stamina"
		Stamina.Parent = Stats
		Stamina.Value = 100 * Melee.Value
		local Def = Instance.new("IntValue")
		Def.Name = "Defend"
		Def.Parent = Stats
		local Agi  = Instance.new("IntValue")
		Agi.Name = "Agility"
		Agi.Parent =Stats
		
		local Df = Instance.new("StringValue")
		Df.Name = "DevilFruit"
		Df.Parent = Stats
		Df.Value = 1
		local HakiObtain = Instance.new("BoolValue")
		HakiObtain.Name = "HakiObtained"
		HakiObtain.Value = false
		HakiObtain.Parent = Stats
		local Point = Instance.new("IntValue")
		Point.Name = "Point"
		Point.Parent = Stats
		Point.Value = 5
		local Cash = Instance.new("IntValue")
		Cash.Name = "Cash"
		Cash.Parent = Stats
		Cash.Value = 100
		local Sword = Instance.new("IntValue")
		Sword.Name = "Sword"
		Sword.Value = 1
		Sword.Parent = Stats
		Melee.Value = 1
		Def.Value = 1
		Agi.Value = 100 * Melee.Value
		
		local Code = player.UserId
		local Data
		local Succes, bugs = pcall(function()
			Data =DataStore:GetAsync(Code)
		end)
		if Succes then
			Melee.Value = Data.Melee
			Def.Value = Data.Def
			Df.Value = Data.Df
			HakiObtain.Value = Data.HakiOb
			Point.Value = Data.Point
			Cash.Value = Data.Cash
			Sword.Value  = Data.Sword
			
			
		else
			error(bugs)
			
		end
	
		
		

		
		
		
		
		
		
	end
end)
function save(code,data)
	local succes ,err = pcall(function()
		DataStore:SetAsync(code,data)
	end)
	
end
game.Players.PlayerRemoving:Connect(function(plr)
	local Code = plr.UserId
	
	
	
	local Data = {
		Melee = ServerStorage:WaitForChild(".playerproperty")[plr.Name].Stats.Melee.Value;
		Sword = ServerStorage:WaitForChild(".playerproperty")[plr.Name].Stats.Sword.Value;
		Def = ServerStorage:WaitForChild(".playerproperty")[plr.Name].Stats.Defend.Value;
		Df = ServerStorage:WaitForChild(".playerproperty")[plr.Name].Stats.DevilFruit.Value;
		HakiOb = ServerStorage:WaitForChild(".playerproperty")[plr.Name].Stats.HakiObtained.Value;
		Point = ServerStorage:WaitForChild(".playerproperty")[plr.Name].Stats.Point.Value;
		Cash = ServerStorage:WaitForChild(".playerproperty")[plr.Name].Stats.Cash.Value;
		
		
	}
	save(Code,Data)
	

end)
game:BindToClose(function()
	for i,v in pairs(ServerStorage:WaitForChild(".playerproperty"):GetChildren()) do
		for i, plr in pairs(game:GetService("Players"):GetChildren()) do
			
			
			local Code = plr.UserId
			local Player_Data = v[plr.Name].Stats
			
			local Data = {
				Melee = ServerStorage:WaitForChild(".playerproperty")[plr.Name].Stats.Melee.Value;
				Sword = ServerStorage:WaitForChild(".playerproperty")[plr.Name].Stats.Sword.Value;
				Def = ServerStorage:WaitForChild(".playerproperty")[plr.Name].Stats.Defend.Value;
				Df = ServerStorage:WaitForChild(".playerproperty")[plr.Name].Stats.DevilFruit.Value;
				HakiOb = ServerStorage:WaitForChild(".playerproperty")[plr.Name].Stats.HakiObtained.Value;
				Point = ServerStorage:WaitForChild(".playerproperty")[plr.Name].Stats.Point.Value;
				Cash = ServerStorage:WaitForChild(".playerproperty")[plr.Name].Stats.Cash.Value;


			}
			save(Code,Data)
			
			
			
		
		end
		end
end)

1 Like

make sure you publish game and enable api access in studio

1 Like

i meant the melee and defend value
do u see i set it to 1 , but in game its set to 0

1 Like

well i dont see you setting the Meleee and defend value i just see youre creating and parenting it only

1 Like
game:BindToClose(function()
	wait(5)
end)

you can just do this for bindtoclose function

i meant , i need the melee, and defend set to 1 not 0

1 Like

so you mean the value of melee and defend not getting saved?

1 Like

i mean the defaut value of the melee is 1 but when i join the game its setting to 0

thats weird lemme check now about this

you must enable api servises and HTTP

HTTP is unnecesarry. Api Services is already ok.

Overall, I think you might wanna re-write your script and organize it,