My script to show how long someone survived is not working. I will label where the error is.
local pLayers = game:GetService("Players")
pLayers.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Time = Instance.new("IntValue")
Time.Name = "Time Alive"
Time.Value = 0
Time.Parent = leaderstats
task.wait()
local humanoid = player.Character.WaitForChild("Humanoid") -- error here
while task.wait(1) do
if humanoid.Health == 0 then
Time.Value = 0
task.wait(3)
else
Time.Value += 1
end
end
end)
its probably because the players character hasnt loaded yet
local pLayers = game:GetService("Players")
pLayers.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Time = Instance.new("IntValue")
Time.Name = "Time Alive"
Time.Value = 0
Time.Parent = leaderstats
player.CharacterAdded:Wait()
local humanoid = player.Character:WaitForChild("Humanoid") -- error here
while task.wait(1) do
if humanoid.Health == 0 then
Time.Value = 0
task.wait(3)
else
Time.Value += 1
end
end
end)
local pLayers = game:GetService("Players")
pLayers.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Time = Instance.new("IntValue")
Time.Name = "Time Alive"
Time.Value = 0
Time.Parent = leaderstats
task.wait()
local character = player.Character or player.CharacterAdded:Wait() --Sets character to character, if nil then it waits for it
local humanoid = character:FindFirstChild("Humanoid")
while task.wait(1) do
if humanoid.Health == 0 then
Time.Value = 0
task.wait(3)
else
Time.Value += 1
end
end
end)