Data values not going up

I have a JSONencode script which saves my data values. This works. My data values are stage, deaths and seconds. The seconds works as it saves and goes up every second by one. I do not want to change my JSONencode script. My deaths script is not working as when I die, it does not go up by one. My checkpoints do not work as when I touch the second checkpoint, the value does not turn into two.
My saving script:

local DSS = game:GetService("DataStoreService")
local DataStore = DSS:GetDataStore("Dev Forum Help2")
local HttpService = game:GetService("HttpService")


game.Players.PlayerAdded:Connect(function(player)
	local obbyData = DataStore:GetAsync(player.UserId .. "-obbyStageProgress")
	local stats = Instance.new("Folder")
	stats.Name = "leaderstats"
	stats.Parent = player
	
	local stage = Instance.new("StringValue")
	stage.Name = "Stage"
	stage.Value = obbyData or 1
	stage.Parent = stats
	
	local wipeouts = Instance.new("IntValue")
	
	wipeouts.Name = "Deaths"
	wipeouts.Value = 0
	wipeouts.Parent = stats
	
	local second = Instance.new("IntValue")

	second.Name = "Seconds"
	second.Value = 0
	second.Parent = stats
	local data
	local success, errormessage = pcall(function()
		data = DataStore:GetAsync(player.UserId.."-DataStore")
		if data then
			local newData = HttpService:JSONDecode(data)
			stage.Value = newData[1]
			wipeouts.Value = newData[2]
			second.Value = newData[3]
		end
	end)

	if success then 
		print("Loaded")
	end
	
	if not success then
		print(errormessage)
	end
end)


game:BindToClose(function()
	local player 
	local c = game.Players:GetPlayers()
	for i = 1,#c do
   		 player = c[i]
	end
	local success, errormessage = pcall(function()
			local Data = {
				player.leaderstats.Stage.Value;	
				player.leaderstats.Deaths.Value;
				player.leaderstats.Seconds.Value;
			}
			
			local newdata = HttpService:JSONEncode(Data)
		
			DataStore:SetAsync(player.UserId.."-DataStore",newdata)
		end)
	if success then 
		print("Saved")
	elseif errormessage then
		print(errormessage)
	end
end)


game.Players.PlayerRemoving:Connect(function(player)
	local success, errormessage = pcall(function()
				local Data = {
				player.leaderstats.Stage.Value;	
				player.leaderstats.Deaths.Value;
				player.leaderstats.Seconds.Value;
			}
		
		local newdata = HttpService:JSONEncode(Data)
		DataStore:SetAsync(player.UserId.."-DataStore",newdata)
	end)
	if success then 
		print("Saved")
	elseif errormessage then
		print(errormessage)
	end
end)

My Deaths Script:

wait(5)
local plrs = game.Players
 -- Change this with a different name.	

print ("Deaths leaderstats working")


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

	
	
	plr.CharacterAdded:Connect(function(char)
		local humanoid = char:FindFirstChild("Humanoid")
		humanoid.Died:Connect(function()
			plr.leaderstats.Deaths.Value = plr.leaderstats.Deaths.Value + 1
		end)
			
		end)		
	end)

My Checkpoints Script:

wait(5)
local dss = game:GetService("DataStoreService")

print ("Checkpoints leaderstats working")
local checkpoints = workspace.Checkpoints


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

	
	local char = plr.Character or plr.CharacterAdded:Wait()
	
	char:WaitForChild("HumanoidRootPart").CFrame = checkpoints[plr.leaderstats.Stage.Value ].CFrame
	
	char.Humanoid.Touched:Connect(function(touch)
				
		if touch.Parent == checkpoints then
			if (tonumber(touch.Name) and tonumber(touch.Name) > tonumber(plr.leaderstats.Stage.Value )) or touch.Name == "End" then
				plr.leaderstats.Stage.Value = touch.Name
					
				
			end
		end
	end)
	
	plr.CharacterAdded:Connect(function(char)
		
		local hrp = char:WaitForChild("HumanoidRootPart")		
		local humanoid = char:WaitForChild("Humanoid")
			
		hrp:GetPropertyChangedSignal("CFrame"):Wait()

		hrp.CFrame = checkpoints[plr.leaderstats.Stage.Value ].CFrame
		
		humanoid.Touched:Connect(function(touch)
				
			if touch.Parent == checkpoints then
				if (tonumber(touch.Name) and tonumber(touch.Name) > tonumber(plr.leaderstats.Stage.Value )) or touch.Name == "End" then
					plr.leaderstats.Stage.Value  = touch.Name
					
					
				end
			end
		end)
	end)	
end)

My seconds script :

wait()
local plrs = game.Players
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("Seconds") -- Change this with a different name.	

print ("Time leaderstats working")
game.Players.PlayerAdded:Connect(function(plr)

	
	
	plr.CharacterAdded:Connect(function(char)
		while true do
			wait(2)
			plr.leaderstats.Seconds.Value = plr.leaderstats.Seconds.Value + 1
		end
			
		end)		
	end)




	
		
		
			







Is it saving put your player moving code before the bind to close code or is it not incrementing

The saving code is working, the deaths are not going up and the checkpoints are not going up.

OK paste this code

On every part you have

local Part = script.Parent

Part.Touched:Connect(function(hit)
       local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
      -- Code here
end)

Other words it only runs when the players character is added so it would not help

1 Like

I put this script in

local Part = script.Parent
local checkpoints = script.Parent.Parent
Part.Touched:Connect(function(hit)
       local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
      local char = plr.Character or plr.CharacterAdded:Wait()
	
	char:WaitForChild("HumanoidRootPart").CFrame = checkpoints[plr.leaderstats.Stage.Value ].CFrame
	char.Humanoid.Touched:Connect(function(touch)
		if touch.Parent == checkpoints then
			if (tonumber(touch.Name) and tonumber(touch.Name) > tonumber(plr.leaderstats.Stage.Value )) or touch.Name == "End" then
				plr.leaderstats.Stage.Value = touch.Name
					
			end
		end
	end)
		
		
	
end)

but the player does not spawn there when they join or die. I still have a server script service script which does this

wait(5)
local dss = game:GetService("DataStoreService")

print ("Checkpoints leaderstats working")
local checkpoints = workspace.Checkpoints


game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		
		local hrp = char:WaitForChild("HumanoidRootPart")		
		local humanoid = char:WaitForChild("Humanoid")
			
		hrp:GetPropertyChangedSignal("CFrame"):Wait()

		hrp.CFrame = checkpoints[plr.leaderstats.Stage.Value ].CFrame
		
		
	end)	
end)