Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why Is DataStore Not Saving When Player Leaves or Dies?

So I have a simple enough question. I have made a datastore in the following script but for some reason when the player dies it does not save the player lives. Can someone please tell me what im doing wrong. Any help is greatly appreciated

local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local PlayerLives = DataStoreService:GetDataStore("PlayerLives")
player = script.Parent.Parent.Parent.Parent
YourPlayer = player.Name
PlayerName = {YourPlayer}
local Reward =  game.ReplicatedStorage.Reward:WaitForChild(PlayerName[1])

Reward.Changed:connect(function(plr)
print ("The Number Value Is Working")
	print("Lives are Zero")
	print(plr)
	
	
pcall(function()
	PlayerLives:SetAsync("PLives", plr)
end)

local Lives = PlayerLives:GetAsync("PLives")
print(Lives)

RewardV = Reward.Value
local LivesLeft = Lives + RewardV
print(LivesLeft)

pcall(function()
PlayerLives:SetAsync(player "PLives", LivesLeft)
end)

Number = script.Parent.Number

Number.Text = LivesLeft
end)

1 answer

Nevermind I answered my own question 5 minutes after I asked it

	pcall(function()
	PlayerLives:SetAsync(player "PLives", LivesLeft)
	end)

Had to just take player out of that line before PLives and it works now!

This discussion is preserved as it was. New answers, comments, and votes are closed.