Help with this script

Hello community, I have a problem with a JumPower Save script, but these come out in the OutPut, I have tried several ways to solve it, but it does not work.

LocalScript:

local DataStores = game:GetService("DataStoreService")
local FirstDataStore = DataStores:GetDataStore("WalkSpeedStorage")

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(Character)
		Character.Humanoid.JumpPower = FirstDataStore:GetAsync(player.UserId) or 16
		FirstDataStore:SetAsync(player.UserId, Character.Humanoid.JumpPower)
		Character.Humanoid.Changed:connect(function()
			FirstDataStore:SetAsync(player.UserId, Character.Humanoid.JumpPower)
		end)
		wait(0.1)
	end)
end)

game.Players.PlayerRemoving:connect(function(player)
	FirstDataStore:SetAsync(player.UserId, player.Character.Humanoid.JumpPower)
end)

Error in the OutPut:

Screenshot_26

W h a t, you shouldn’t be using SetAsync everytime the Character’s Humanoid changes, also you’re requesting too often which results in that error

What can I use instead of SetAsync()

You already have a PlayerRemoving function which should save the Data, so you don’t need that Humanoid.Changed event

Use GetAsync instead inside the PlayerAdded function

And I’d also recommend using pcall functions to ensure that your Data will save, cause sometimes it will not work properly without wrapping it in a pcall

To OP and @JackscarIitt , in the very rare case that PlayerRemoving fails to fire, you should implement occasional auto saving (I’d suggest every 2 minutes). It could look something like this

while true do
    for _,v in ipairs(game.Players:GetChildren()) do
        -- Save data
        wait(120)
    end
end