Datastore not saving Player's Walk Speed

Do I have to save the speed variable in my Datastore?

Please notice to my edit, it is important.

The change was, we want to load the data outside of the CharacterAdded event.

Yes, and you then do some checks, to see when hes back, if he has data or not, and load their speed accordingly.

Notice to more changes I did, now it works 100%

I can just put my whole script here and you can fix the Walk Speed thing.

Final script :

local DataStore = game:GetService("DataStoreService"):GetDataStore("SpeedData")

game.Players.PlayerAdded:Connect(function(Player)
	local speedData = DataStore:GetAsync("WalkSpeed-"..Player.UserId)
	local SpeedValue = Instance.new("IntValue",Player)
	SpeedValue.Name = "PlayerSpeed"
	
	
	
	local success,error = pcall(function()
		SpeedValue.Value = speedData
	end)
	if error then
		SpeedValue.Value = 16
	end
	
	Player.CharacterAdded:Connect(function(Char)
		local hum = Char:WaitForChild("Humanoid")
		if hum then
			hum.WalkSpeed = SpeedValue.Value
			SpeedValue.Changed:Connect(function()
				hum.WalkSpeed = SpeedValue.Value
			end)
		end
		
	end)
end)

game.Players.PlayerRemoving:Connect(function(Player)
	local success,error = pcall(function()
		DataStore:SetAsync("WalkSpeed-"..Player.UserId,Player.PlayerSpeed.Value)
	end)
	if not success then
		warn(error)
	else
		print(success)
	end
end)
1 Like
local DataStoreService = game:GetService("DataStoreService")
local PlayerSave = DataStoreService:GetDataStore("PlayerSave")
local RemoteEvents = game.ReplicatedStorage.RemoteEvents
local SpeedMultiplier = RemoteEvents.SpeedMultiplier

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		task.wait()
		local PlayerSpeed = Character.Humanoid.WalkSpeed
		local leaderstats = Player.leaderstats
		local Clicks = leaderstats.Clicks
		local BaseStats = Player.BaseStats
		local Speed = BaseStats.Speed
		local ClicksData,WalkSpeed,Restarts,ButtonPresses
		local success, errormessage = pcall(function()
			ClicksData = PlayerSave:GetAsync("Clicks-"..Player.UserId)
			Restarts = PlayerSave:GetAsync("Restarts-"..Player.UserId)
			ButtonPresses = PlayerSave:GetAsync("ButtonPresses-"..Player.UserId)
			WalkSpeed = PlayerSave:GetAsync("WalkSpeed-"..Player.UserId)
		end)
		if success then
			if ClicksData then
				Player.leaderstats.Clicks.Value = ClicksData
			else
		end
			if success then
				warn(errormessage)
				if WalkSpeed == nil then
					Player.Character.Humanoid.WalkSpeed = 16
					print("This is DataStore WalkSpeed "..WalkSpeed)
				else
					Player.Character.Humanoid.WalkSpeed = WalkSpeed
					local NewValue = Instance.new("IntValue")
					NewValue.Name = "Walkspeed"
					NewValue.Value = WalkSpeed
					Character.Humanoid.WalkSpeed = WalkSpeed
					NewValue.Parent = Player
					Character.Humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
						NewValue.Value = Character.Humanoid.WalkSpeed
					end)
				end
				if success then
					if ButtonPresses then
						Player.BaseStats.ButtonPresses = ButtonPresses
					end
					if success then
						if Restarts then
							Player.leaderstats.Restarts.Value = Restarts
						else
							Player.leaderstats.Restarts.Value = 1
						end
					end
				end
			end
		end
	end)
	
	game.Players.PlayerRemoving:Connect(function(Player)
		local success, errormessage = pcall(function()
			game:BindToClose(function()
			PlayerSave:SetAsync("Clicks-"..Player.UserId,Player.leaderstats.Clicks.Value)
			PlayerSave:SetAsync("Restarts-"..Player.UserId,Player.leaderstats.Restarts.Value)
			warn("Binded to close. I saved everything!")
			PlayerSave:SetAsync("WalkSpeed-"..Player.UserId,Player.Character.Humanoid.WalkSpeed)
			PlayerSave:SetAsync("ButtonPresses-"..Player.UserId,Player.BaseStats.ButtonPresses.Value)
			end)
		end)
	end)
end)

What happens here, is we set the WalkSpeed accordingly to our value’s value. And when that value is changed, we change the walkspeed accordingly

Instead of using too many calls, you just should have a table, and save all your values that inside of that table.

Can you show me an example with my script?

How do you save Tables to datastore?, hopefully it can help you.

I apologize man, I need to go, but you can use the principle of this article and my example to help you.

Good luck!

Yeah, I recommend having a single datastore named something like “MainData” and save it as a table with the real data inside like WalkSpeed and ClicksData.