Why is data not saving?

Thank you for your feedback! :smiley:
However, I do think that this would help them a-lot, has there are a-lot of things that they don’t have. (BindToClose, pcalls, etc.)

1 Like

Yea so that is your issue! Your looking for the value “jump” in the leaderstats folder but the value is called “JumpPowerr” so you should be getting the value of that.

Thats why it says there is nothing called “jump” inside of the folder cuz its not called that it is called “JumpPowerr”

1 Like

Your searching for “leaderstats.jump” but you named Jump value JumpPowerr so call leaderstats.JumpPowerr.Value

1 Like

Yes I 100% do agree they should read it as it is quite clear they don’t understand how to use datastores that well.

2 Likes

ok so…
when i leave it no save :<
script:

local DataStoreService = game:GetService("DataStoreService")
local playerData = DataStoreService:GetDataStore("PlayerData")


local function onPlayerJoin(player) -- Runs when players join
	local leaderstats = Instance.new("Folder") 
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	local jump = Instance.new("IntValue") 
	jump.Name = "JumpPowerr"
	jump.Parent = leaderstats
	
	local playerUserId = "Player_" .. player.UserId 
	local data = playerData:GetAsync(playerUserId) 
	if data then

		jump.Value = data
	else
		jump.Value = 0
	end
end

local function onPlayerExit(player) 
	local success, err = pcall(function()
		local playerUserId = "Player" .. player.UserId
		playerData:SetAsync(playerUserId, player.leaderstats.JumpPowerr.Value) 
	end)

	if not success then
		warn(err) 
	end
end

game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerExit)

it shows no error

This is in a server script correct?

1 Like

Hi Are you testing it on Studio? Data Does not save when leaving on studio test it in game

1 Like

Um are you sure data does not save in-studio? I have never had an issue like that before; data always save for me in-studio.

1 Like

In All my projects and datastores when I leave the game (On studio) Data does not save, for make it work and save i need always to test in Game.

game.Players.PlayerRemoving:Connect()

doesn’t run always when leaving on studio.

1 Like

yes it is
awefeawf

Well that is strange. I legit tested something yesterday in-studio and it saved in the datastore. Not sure why it is different for you.

@OfficerlSwearShes19 I suggest doing what Sonostrando said then as it might be that issue.

1 Like

should i add the playerexit?

Yes you just need to test you’re script

My it was just an example of the playerleaving function

1 Like

i added it tested it in main game and it still not working …

Ok I Got It you Typed wrong the Key

local DataStoreService = game:GetService("DataStoreService")
local playerData = DataStoreService:GetDataStore("PlayerData")


local function onPlayerJoin(player) -- Runs when players join
	local leaderstats = Instance.new("Folder") 
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	local jump = Instance.new("IntValue") 
	jump.Name = "JumpPowerr"
	jump.Parent = leaderstats

	local playerUserId = "Player_" .. player.UserId 
	local data = playerData:GetAsync(playerUserId) 

	if data then

		jump.Value = data
	else
		jump.Value = 0
	end
end

local function onPlayerExit(player) 
	local success, err = pcall(function()
		local playerUserId = "Player_" .. player.UserId
		playerData:SetAsync(playerUserId, player.leaderstats.JumpPowerr.Value) 
	end)

	if not success then
		warn(err) 
	end
end

game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerExit)

Copy and paste this inside you’re server script, basicaly on onPlayerExit → Var: playerUserId first it was “Player” and not “Player_”

Edit: Forgot to remove print(data) → Removed

1 Like

i think the local script is causing the problem

This It’s a server script, you can’t put that on a local script

1 Like

i made it so every time u jump u get 10 jumppower on a local script will that power not be saved?

Well, If you’re modifing the value on the client, The data will remain 0 on the server and when you will leave the server will read “0” instead you should modify the value for example via Server Script or Via localscript by firing an RemoteEvent And then have the server modify the value when receives the event

2 Likes