Why do i have a nil value at line 41 and 50?
Asked by
4 years ago Edited 4 years ago
local DataStoreService = game:GetService("DataStoreService")
local PDS = DataStoreService:GetDataStore("PointSim1235")
game.Players.PlayerAdded:Connect(function(NewPlayer)
local Key = "PDS-" .. NewPlayer.UserId
local GetSave = PDS:GetAsync(Key)
local leaderstats = Instance.new("Folder", NewPlayer)
leaderstats.Name = "leaderstats"
local points = Instance.new("IntValue", leaderstats)
points.Name = "Points"
local Rebirths = Instance.new("IntValue", leaderstats)
Rebirths.Name = "Rebirths"
Rebirths.Value = 1
local PlayerStats = Instance.new("Folder", NewPlayer)
PlayerStats.Name = "Playerstats"
local ClickBonus = Instance.new("IntValue", PlayerStats)
ClickBonus.Name = "ClickBonus"
NewPlayer.CharacterAdded:Connect(function()
local character = NewPlayer.Character
local At1 = Instance.new("Attachment", character:WaitForChild("Head"))
local At2 = Instance.new("Attachment", character:WaitForChild("HumanoidRootPart"))
At1.Name = "At1"
At2.Name = "At2"
end)
if GetSave then --load data
points.Value = GetSave[1]
Rebirths.Value = GetSave[2]
ClickBonus.Value = GetSave[3]
print("Data Loaded For " .. NewPlayer.Name)
else
points.Value = GetSave[0]
Rebirths.Value = GetSave[1]
ClickBonus.Value = GetSave[0]
print("New Data Created For " .. NewPlayer.Name)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
print("Saving Data For " .. player.Name)
local Key = "PDS-" .. NewPlayer.UserId
local Stats1 = player.leaderstats
local Stats2 = player.Playerstats
local DataToSave = {}
for _, Stat in pairs(Stats1:GetChildren()) do
table.insert(DataToSave, Stat.Value)
warn("Player Left, Saving " .. Stat.Name .. " | " .. Stat.Value)
end
for _, Stat in pairs(Stats2:GetChildren()) do
table.insert(DataToSave, Stat.Value)
warn("Player Left, Saving " .. Stat.Name .. " | " .. Stat.Value)
end
PDS:SetAsync(Key, DataToSave)
end)