Script saying there is a 'nil' value in this script, can someone help?
I am trying to create a script that makes a data storage for a player when he/she joins the game and update their health every second inside another IntValue, but the script is saying that there is a 'nil' value in the script.
01 | local plr = game.Players.LocalPlayer |
04 | plr.CharacterAdded:connect( function (char) |
05 | local Humanoid = char:WaitForChild( 'Humanoid' ) |
06 | local plrName = plr.Name |
07 | local PlayerData = game.ServerStorage.PlayerNameStorage:WaitForChild(plrName.. "Data" ) |
08 | local PlayerNameValue = PlayerData:WaitForChild(plrName.. "NameValue" ) |
09 | local HealthIntValue = PlayerData:WaitForChild(plrName.. "HealthValue" ) |
10 | local MaxHealthIntValue = PlayerData:WaitForChild(plrName.. "MaxHealthValue" ) |
14 | if Humanoid ~ = nil then |
15 | if Humanoid.Health > 0 then |
16 | HealthIntValue.Value = Humanoid.Health |
18 | elseif Humanoid.Health < = 0 then |
19 | HealthIntValue.Value = 0 |
22 | elseif Humanoid = = nil then |
23 | print ( "'Humanoid' not found; all relating objects removed." ) |
25 | elseif char = = nil then |
26 | print ( "'char' not found; all relating objects removed." ) |
28 | elseif plr = = nil then |
29 | print ( "'plr' not found; all relating objects removed." ) |
Here is the whole code:
01 | game.Players.PlayerAdded:connect( function (plr) |
02 | local plrName = plr.Name |
03 | if game.ServerStorage.PlayerNameStorage ~ = nil then |
04 | local PlayerData = Instance.new( 'Folder' ) |
05 | PlayerData.Parent = game.ServerStorage.PlayerNameStorage |
06 | PlayerData.Name = plrName.. "Data" |
07 | local PlayerNameValue = Instance.new( 'StringValue' ) |
08 | PlayerNameValue.Parent = PlayerData |
09 | PlayerNameValue.Name = plrName.. "NameValue" |
10 | PlayerNameValue.Value = plrName |
11 | local HealthIntValue = Instance.new( 'IntValue' ) |
12 | HealthIntValue.Parent = PlayerData |
13 | HealthIntValue.Name = plrName.. "HealthValue" |
14 | local MaxHealthIntValue = Instance.new( 'IntValue' ) |
15 | MaxHealthIntValue.Name = plrName.. "MaxHealthValue" |
16 | MaxHealthIntValue.Parent = PlayerData |
17 | plr.CharacterAdded:connect( function (char) |
18 | local Humanoid = char:WaitForChild( 'Humanoid' ) |
19 | if Humanoid.Health > 0 then |
20 | HealthIntValue.Value = Humanoid.Health |
21 | MaxHealthIntValue.Value = Humanoid.MaxHealth |
27 | game.Players.PlayerRemoving:connect( function (plr) |
28 | local plrName = plr.Name |
29 | if game.ServerStorage.PlayerNameStorage:FindFirstChild(plrName.. "Data" ) ~ = nil then |
30 | local PlayerData = game.ServerStorage.PlayerNameStorage:FindFirstChild(plrName.. "Data" ) |
36 | local plr = game.Players.LocalPlayer |
39 | plr.CharacterAdded:connect( function (char) |
40 | local Humanoid = char:WaitForChild( 'Humanoid' ) |
41 | local plrName = plr.Name |
42 | local PlayerData = game.ServerStorage.PlayerNameStorage:WaitForChild(plrName.. "Data" ) |
43 | local PlayerNameValue = PlayerData:WaitForChild(plrName.. "NameValue" ) |
44 | local HealthIntValue = PlayerData:WaitForChild(plrName.. "HealthValue" ) |
45 | local MaxHealthIntValue = PlayerData:WaitForChild(plrName.. "MaxHealthValue" ) |
49 | if Humanoid ~ = nil then |
50 | if Humanoid.Health > 0 then |
51 | HealthIntValue.Value = Humanoid.Health |
53 | elseif Humanoid.Health < = 0 then |
54 | HealthIntValue.Value = 0 |
57 | elseif Humanoid = = nil then |
58 | print ( "'Humanoid' not found; all relating objects removed." ) |
60 | elseif char = = nil then |
61 | print ( "'char' not found; all relating objects removed." ) |
63 | elseif plr = = nil then |
64 | print ( "'plr' not found; all relating objects removed." ) |