Data Store huamnoid walkSpeed and jumpHeight

I am having trouble using data store to save the players walk speed and jump height could someone help? (There are no errors by the way)

Code:

local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")


game.Players.PlayerAdded:Connect(function(player)
	local Character = workspace:WaitForChild(player.Name)

	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local PetsFolder = Instance.new("Folder")
	PetsFolder.Name = "Pets"
	PetsFolder.Parent = player

	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Parent = leaderstats

	local jumps = Instance.new("IntValue")
	jumps.Name = "Jumps"
	jumps.Parent = leaderstats

	local rebirths = Instance.new("IntValue")
	rebirths.Name = "Rebirths"
	rebirths.Parent = leaderstats

	local data
	local data1
	local data2
	local data3
	local data4
	local success, errormessage = pcall(function()
		data = myDataStore:GetAsync(player.UserId.."-coins")
		data1 = myDataStore:GetAsync(player.UserId.."-rebirths")
		data2 = myDataStore:GetAsync(player.UserId.."-jumps")
		data3 = myDataStore:GetAsync(player.UserId.."-jumpHeight")
		data4 = myDataStore:GetAsync(player.UserId.."-walkSpeed")
	end)

	if success then
		coins.Value = data
		rebirths.Value = data1
		jumps.Value = data2
		Character.Humanoid.JumpHeight = data3
		Character.Humanoid.WalkSpeed = data4
	else
		print("There was an error getting your data")
		warn(errormessage)
	end	
	
	player.CharacterRemoving:Connect(function(player1)
		local humanoid = player.Character:FindFirstChild("Humanoid")
		local success, errormessage = pcall(function()
			myDataStore:SetAsync(player.UserId.."-jumpHeight",humanoid.JumpHeight)
			myDataStore:SetAsync(player.UserId.."-walkSpeed",humanoid.WalkSpeed)
		end)

		if success then
			print("Player data was successfully saved!")
		else
			print("There was an error while saving data")
			warn(errormessage)
		end
	end)
	
	
end)

game.Players.PlayerRemoving:Connect(function(player)

	local success, errormessage = pcall(function()
		myDataStore:SetAsync(player.UserId.."-coins",player.leaderstats.Coins.Value)
		myDataStore:SetAsync(player.UserId.."-rebirths",player.leaderstats.Rebirths.Value)
		myDataStore:SetAsync(player.UserId.."-jumps",player.leaderstats.Jumps.Value)
	end)

	if success then
		print("Player data was successfully saved!")
	else
		print("There was an error while saving data")
		warn(errormessage)
	end
end)

You might be calling too many requests to the server I would suggest putting such items in a table.

local Table = {
items here1, items here2
}
1 Like

How would you do that im unsure

what would item here be?

What is item here what is the table holding


local Speed = 16
local Walk = 5
local Money = 700

local Table = {
	Speed,
	Walk,
	Money
}

local plr = nil
ds:SetAsync(plr.UserId, Table)

Sorry but is “ds” data store service or my data store

Your datastore is mentioned here. If you have any further problems like how to mention a specific item; the top item is Table[1] and so on.

1 Like

I get the error 104: Cannot store Array in data store. Data stores can only accept valid UTF-8 characters.

I think I’m doing something wrong but if you could rewrite it for me or tell me what to change that would be great I am terrible with datastores

Script

local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")


game.Players.PlayerAdded:Connect(function(player)
	local Character = workspace:WaitForChild(player.Name)
	local WalkSpeed = Character.Humanoid.WalkSpeed
	local JumpHeight = Character.Humanoid.JumpHeight

	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local PetsFolder = Instance.new("Folder")
	PetsFolder.Name = "Pets"
	PetsFolder.Parent = player

	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Parent = leaderstats

	local jumps = Instance.new("IntValue")
	jumps.Name = "Jumps"
	jumps.Parent = leaderstats

	local rebirths = Instance.new("IntValue")
	rebirths.Name = "Rebirths"
	rebirths.Parent = leaderstats

	local Table = {
		coins,
		jumps,
		rebirths,
		WalkSpeed,
		JumpHeight
		
	}
	local success, errormessage = pcall(function()
		myDataStore:SetAsync(player.UserId, Table)
	end)

	if success then
		coins.Value = Table[1]
		jumps.Value = Table[2]
		rebirths.Value = Table[3]
		Character.Humanoid.WalkSpeed = Table[4]
		Character.Humanoid.JumpHeight = Table[5]
	else
		print("There was an error getting your data")
		warn(errormessage)
	end	
	
	player.CharacterRemoving:Connect(function(player1)
		local humanoid = player.Character:FindFirstChild("Humanoid")
		local success, errormessage = pcall(function()
			myDataStore:GetAsync(player.UserId.."-jumpHeight",humanoid.JumpHeight)
			myDataStore:GetAsync(player.UserId.."-walkSpeed",humanoid.WalkSpeed)
		end)

		if success then
			print("Player data was successfully saved!")
		else
			print("There was an error while saving data")
			warn(errormessage)
		end
	end)
	
	
end)

game.Players.PlayerRemoving:Connect(function(player)

	local success, errormessage = pcall(function()
		myDataStore:SetAsync(player.UserId.."-coins",player.leaderstats.Coins.Value)
		myDataStore:SetAsync(player.UserId.."-rebirths",player.leaderstats.Rebirths.Value)
		myDataStore:SetAsync(player.UserId.."-jumps",player.leaderstats.Jumps.Value)
	end)

	if success then
		print("Player data was successfully saved!")
	else
		print("There was an error while saving data")
		warn(errormessage)
	end
end)
game.Players.PlayerRemoving:Connect(function(player)

	local success, errormessage = pcall(function()
       local jumps = player.leaderstats.Jumps.Value
       local rebirths = player.leaderstats.Rebirths.Value
       local coins = player.leaderstats.Coins.Value
		local Table = {
           jumps,
           rebirths,
           coins
}
   myDataStore:SetAsync(player.UserId, Table)
	end)

	if success then
		print("Player data was successfully saved!")
	else
		print("There was an error while saving data")
		warn(errormessage)
	end
end)

For other items I would suggest creating another data store if they are saved differently.

1 Like

I get the same error coming from this part

local Table = {
		coins,
		jumps,
		rebirths,
		WalkSpeed,
		JumpHeight
		
	}
	local success, errormessage = pcall(function()
		myDataStore:SetAsync(player.UserId, Table)
	end)

	if success then
		coins.Value = Table[1]
		jumps.Value = Table[2]
		rebirths.Value = Table[3]
		Character.Humanoid.WalkSpeed = Table[4]
		Character.Humanoid.JumpHeight = Table[5]
	else
		print("There was an error getting your data")
		warn(errormessage)
	end	

Please save this using a different data store. Use the same technique above

player.CharacterRemoving:Connect(function(player1)
		local humanoid = player.Character:FindFirstChild("Humanoid")
		local success, errormessage = pcall(function()
			myDataStore2:GetAsync(player.UserId, {humanoid.JumpHeight, humanoid.WalkSpeed}

		end)

		if success then
			print("Player data was successfully saved!")
		else
			print("There was an error while saving data")
			warn(errormessage)
		end
	end)

After getting this Data store, call the variables by doing: jump height as TableNew[1] and Walkspeed TableNew[2]

I tried to follow your instructions on to my script but it still does not work but it does not even get any errors

Code:

local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
local myDataStore2 = DataStoreService:GetDataStore("HumanoidStats")


game.Players.PlayerAdded:Connect(function(player)
	local Character = workspace:WaitForChild(player.Name)
	local WalkSpeed = Character.Humanoid.WalkSpeed
	local JumpHeight = Character.Humanoid.JumpHeight

	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local PetsFolder = Instance.new("Folder")
	PetsFolder.Name = "Pets"
	PetsFolder.Parent = player

	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Parent = leaderstats

	local jumps = Instance.new("IntValue")
	jumps.Name = "Jumps"
	jumps.Parent = leaderstats

	local rebirths = Instance.new("IntValue")
	rebirths.Name = "Rebirths"
	rebirths.Parent = leaderstats
	
	local success, errormessage = pcall(function()
		local humanoid = player.Character:FindFirstChild("Humanoid")
		local WalkSpeed = humanoid.WalkSpeed
		local JumpHeight = humanoid.JumpHeight
		local Table = {
			WalkSpeed,
			JumpHeight
		}
		myDataStore:GetAsync(player.UserId, Table)
	end)

	if success then
		print("Player data was successfully saved!")
	else
		print("There was an error while saving data")
		warn(errormessage)
	end
	
	player.CharacterRemoving:Connect(function(player1)
		local humanoid = player.Character:FindFirstChild("Humanoid")
		local success, errormessage = pcall(function()
			myDataStore2:GetAsync(player.UserId, {humanoid.JumpHeight, humanoid.WalkSpeed})
		end)

		if success then
			print("Player data was successfully saved!")
		else
			print("There was an error while saving data")
			warn(errormessage)
		end
	end)

end)

game.Players.PlayerRemoving:Connect(function(player)

	local success, errormessage = pcall(function()
       local jumps = player.leaderstats.Jumps.Value
       local rebirths = player.leaderstats.Rebirths.Value
       local coins = player.leaderstats.Coins.Value
		local Table = {
           jumps,
           rebirths,
           coins
}
   myDataStore:SetAsync(player.UserId, Table)
	end)

	if success then
		print("Player data was successfully saved!")
	else
		print("There was an error while saving data")
		warn(errormessage)
	end
end)

That’s weird I tried using your script all I recieved was 02:55:31.964 Player data was successfully saved!.

Ya I am not sure how to fix it