Jumppower saves if u leave the game?

i dont know what to do can someone explain how to save jumppower if someone leaves the game

Try this maybe:

local d = game:GetService("DataStoreService"):GetDataStore()
game.Players.PlayerAdded:Connect(function(p)
if d:GetAsync(p.userId) ~= nil then
p.Character:WaitForChild("Humanoid").JumpPower = d:GetAsync(p.UserId)[1]
end
end)
game.Players.PlayerRemoving:Connect(function(p)
d:SetAsync(p.UserId,p.Character.Humanoid.JumpPower)
end)
2 Likes

nop

1 Like

Can you share the output error?

2 Likes

“argument 1 missing or nil”

1 Like
local d = game:GetService("DataStoreService"):GetDataStore("JumpPower")

game.Players.PlayerAdded:Connect(function(p)
	if d:GetAsync(p.userId) ~= nil then
		p.CharacterAdded:Wait()
		p.Character:WaitForChild("Humanoid").JumpPower = d:GetAsync(p.UserId)[1]
	end
end)

game.Players.PlayerRemoving:Connect(function(p)
	d:SetAsync(p.UserId,p.Character.Humanoid.JumpPower)
end)
2 Likes

Is the game published, if its not publish it.

1 Like

both are in serverscripts and normal scripts
script1:

local d = game:GetService("DataStoreService"):GetDataStore("JumpPower")

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

	if d:GetAsync(p.userId) ~= nil then
		p.CharacterAdded:Wait()
		p.Character:WaitForChild("Humanoid").JumpPower = d:GetAsync(p.UserId)[1]
	end
end)

game.Players.PlayerRemoving:Connect(function(p)
	d:SetAsync(p.UserId,p.Character.Humanoid.JumpPower)
end)

script2:

game.Players.PlayerAdded:Connect(function(plr)
	
wait(5)
	while wait(1) do
		
		plr.Character.Humanoid.JumpPower = plr.Character.Humanoid.JumpPower + 10
		end
		
	
	end)

api enables is on

Okay, but is the game published?

1 Like

yes it is

Hm, sadly im not sure in that case.

1 Like

Remove the [1] after the d:GetAsync(p.UserId). You’re not saving a table to the datastore so the key will simply reference to the ONE thing you have saved.

Also, try to use more meaningful variable names to improve the readability of your code. Instead of “p”, use “plr” or “player” - try to avoid meaningless single letter variables.

2 Likes

still not working
script:

local d = game:GetService("DataStoreService"):GetDataStore("JumpPower")

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

	if d:GetAsync(plr.userId) ~= nil then
		plr.CharacterAdded:Wait()
		plr.Character.Humanoid.JumpPower = d:GetAsync(plr.UserId)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	d:SetAsync(plr.UserId,plr.Character.Humanoid.JumpPower)
end)

ServerScriptService.Script:6: attempt to index nil with ‘Humanoid’

Assuming this is coming from the script you posted, you’re going to want to add back the :WaitForChild("Humanoid") on the effected line. Let me know if this works out for you.

local jumpDatastore = game:GetService("DataStoreService"):GetDataStore("JumpPower")

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

	if jumpDatastore:GetAsync(plr.userId) ~= nil then
		plr.CharacterAdded:Wait()
		plr.Character:WaitForChild("Humanoid").JumpPower = jumpDatastore:GetAsync(plr.UserId)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	
	jumpDatastore:SetAsync(plr.UserId,plr.Character.Humanoid.JumpPower)
end)

However, it looks like the error ServerScriptService.Script:6: attempt to index nil with ‘Humanoid’ is coming from the script you’re using to edit the JumpPower of a player every second that you posted earlier. Try the following instead:

game.Players.PlayerAdded:Connect(function(plr)
	wait(5)
	while wait(1) do
		if plr.Character.Humanoid then
		plr.Character.Humanoid.JumpPower = plr.Character.Humanoid.JumpPower + 10
		end
	end
	


end)

Personally I’d recommend changing a few things for best practice sake (I just copy and pasted your original script and made changes), but overall this should accomplish what you’re trying to do.

local ds = game:GetService("DataStoreService"):GetDataStore("JumpPower")
game.Players.PlayerAdded:Connect(function(plr)
	local data = ds:GetAsync(plr.userId)
	plr.CharacterAdded:Connect(function(char)
		if data then
			if char.Parent ~= workspace then char.AncestryChanged:Wait() end
			char:WaitForChild("Humanoid").JumpPower = data
		end
	end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
	ds:SetAsync(plr.UserId,plr.Character.Humanoid.JumpPower)
end)