I have had some trouble with my DataStore as mentioned in a previous post, this time the error is different. There are no error messages however whenever I try to save data when a person leaves, in this case; JumpPower it always returns as 0. Any help is appreciated
local DataStoreService = game:GetService("DataStoreService")
local MyDataStore1 = DataStoreService:GetDataStore("myDataStore")
game:WaitForChild("Players").PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local JumpPower = Instance.new("IntValue")
JumpPower.Parent = leaderstats
JumpPower.Name = "JumpPower"
JumpPower.Value = 0
local playerUsedId = player.UserId
--Load Data
local data
local success, errormessage = pcall(function()
data = MyDataStore1:GetAsync(playerUsedId)
end)
if success then
JumpPower.Value = data
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUsedId = "Player"..player.UserId
local data = player.leaderstats.JumpPower.Value
local success, errormessage = pcall(function()
MyDataStore1:SetAsync(playerUsedId, data)
end)
if success then
print("Data Successfully Saved")
print(data)
else
print("There was an error")
warn(errormessage)
end
end)