Hello,
I am working on a script that datastores a humanoids death via bool value. When you kill it, the value becomes true, and when you rejoin it goes to the health it was before. But, for some reason, I ran into a error when loading it. They are in two different scripts. This script is inside the dummy, and the error on line 3 is
attempt to index nil with 'Value'
Here is the script:
game.Players.PlayerAdded:Connect(function(Player)
local value = script.Parent:FindFirstChild("IsDead")
if value.Value == true then
script.Parent.Humanoid.Health = 0
print("Dead")
end
end)
script.Parent.Humanoid.Died:Connect(function()
local value = script.Parent:FindFirstChild("IsDead")
value.Value = true
end)
Here is the data storing script:
local dataStores = game:GetService("DataStoreService")
local dataStore = dataStores:GetDataStore("Datastar")
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
local bool = Instance.new("BoolValue")
bool.Name = "IsDead"
bool.Parent = workspace.dum2
local data
local success, result = pcall(function()
data = dataStore:GetAsync("Player_"..player.UserId)
end)
if success then
if data then
print(result)
bool.Value = data
else
print(result)
bool.Value = false
end
else
warn(result)
end
end)
players.PlayerRemoving:Connect(function(player)
local success, result = pcall(function()
dataStore:SetAsync("Player_"..player.UserId, player.Bool.Value)
end)
if success then
print(result)
else
warn(result)
end
end)
game:BindToClose(function()
for _, player in ipairs(players:GetPlayers()) do
local success, result = pcall(function()
dataStore:SetAsync("Player_"..player.UserId, player.Bool.Value)
end)
if success then
print(result)
else
warn(result)
end
end
end)