WalkSpeed Saving Problem!

here is the code:

local rem = game:GetService('ReplicatedStorage'):WaitForChild('RemoteEvent')
local multiplier = require(game:GetService('ServerStorage').ModuleScript)
local datastore = game:GetService('DataStoreService')
local playersave = datastore:GetDataStore('DataSaver')
local deb = false

game.Players.PlayerAdded:Connect(function(player)
	local char = player.Character or player.CharacterAdded:Wait()
	local hum = char.Humanoid

	char:WaitForChild('Humanoid').WalkSpeed = 1.5


	local leaderstats = Instance.new('Folder', player)
	leaderstats.Name = 'leaderstats'
	
	local walkspeed = Instance.new('NumberValue', player)
	walkspeed.Name = 'WalkSpeed'

	local dias = Instance.new('IntValue', player)
	dias.Name = 'Diamond'

	local coins = Instance.new('IntValue', player)
	coins.Name = 'Coins'

	local reb = Instance.new('IntValue', leaderstats)
	reb .Name = 'Rebirth'
	
	walkspeed.Value = hum.WalkSpeed
	
	local function speedstring()
		walkspeed.Value = hum.WalkSpeed
	end

	hum:GetPropertyChangedSignal("WalkSpeed"):Connect(speedstring)
	
	local data
	local suc, er = pcall(function()
		data = playersave:GetAsync(player.UserId)
	end)

	if suc then
		print('YEs')
		if data then
			walkspeed.Value = data.WalkSpeed
		end
	else
		print('NAH')
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local data = {
		WalkSpeed = player.WalkSpeed.Value;
	}
	
	local suc, er = pcall(function()
		playersave:SetAsync(player.UserId, data)
	end)
	
	if suc then
		print('YES DATA SAVED')
	else
		print('NAH data didnt saved')
	end
end)

I have no idea what you need help with. But you should check out DataStore2 because you have a saving issue!

1 Like

i just want to save the players walkspeed when they leave