For some context, its a server script and its in serverscriptservice. heres a snippet of the code where the error is, along with the entire script (i have honestly no idea whats wrong with it
if success then
strength.Value = data.Strength -- this is the error
else
the entire script
local DataStoreService = game:GetService("DataStoreService")
local SaveDataStore = DataStoreService:GetDataStore("SaveData7")
game.Players.PlayerAdded:Connect(function(player)
local data2 = Instance.new("Folder")
data2.Name = "Data2"
data2.Parent = player
local strength = Instance.new("IntValue")
strength.Name = "Strength"
strength.Value = 0
strength.Parent = data2
local playerUserId = "Player_"..player.UserId
local data
local success , errormessage = pcall(function()
data = SaveDataStore:GetAsync(playerUserId)
end)
print("2242")
if success then
strength.Value = data.Strength
else
print("there was an error while saving your data.")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = "Player_"..player.UserId
local data = {
strength = player.Data.Strength.Value
}
local success,errormessage = pcall(function()
SaveDataStore:SetAsync(playerUserId,data)
end)
if success then
print("data saved gg ez")
else
print("there was an error")
warn(errormessage)
end
end)

1 comment
yeah although you need to run a loop for each player in the server as
playervariable is not defined, do same but with ipairs loop for game:GetService('Players'):GetPlayers()'