Hello developers, I'm unsure how to save data in :BindToClose(). I've tried ways such as:
game:BindToClose(function()
local Player = game:GetService("Players"):GetPlayers()
local playerid = "Player_"..Player.UserId
local data = Player.leaderstats.deaths.Value
local success, errormessage = pcall(function()
HisDataStore:SetAsync(playerid, data)
end)
if success then
print("Data has been successfully saved!")
else
print("Data has not been saved, negative!")
warn(errormessage)
end
end)
I've tried this way but doesn't work. Gives the error 'attempt to concatenate string with nil' on the line local playerid = "Player_"..Player.UserId
I can see the mistake but I am rather confused how to fix it.

1 comment
TIP: When a question is solved by you, it's good to write [Solved] or [Answered] at the front or end of the question, so that it won't be marked as unanswered.