I keep getting this error
Workspace.ServerScript:98: attempt to index nil with 'MaxHealth'
the error is coming from this function
function ImplimentData(Player, Humanoid) for RankName, RankTable in pairs(DataModule.Rank) do if Update == false then if RankTable.Name == Player.Data.Rank.Value then Humanoid.MaxHealth = RankTable.MaxHealth -- this is line 98 end else if RankTable.Name == Player.Data.Rank.Value then if Player.Data.Exp.Value >= RankTable.ExpLimit then local Difference = Player.Data.Exp.Value - RankTable.ExpLimit UpdateRankData(Player, RankTable.NextRank) Player.Data.Exp.Value = Difference UpdateExpData(Player, Player.Data.Exp.Value) end end end Update = false end end
I identified Humanoid in lines 201 - 209
Players.PlayerAdded:Connect(function(Player) -- lines 201 DataCreate(Player) GetData(Player) Player.CharacterAdded:Connect(function(Character) repeat wait() until Character:FindFirstChild("Humanoid") local Humanoid = Character.Humanoid ImplimentData(Player, Humanoid) end) end) -- lines 209
DataModule is a ScriptModule in ServerStorage I named it DataModule in ServerStorage but the table name is DataProperties. This is the code
local DataProperties = { Rank = { F = { Name = "F", MaxHealth = 150, ExpLimit = 1000, NextRank = "E" }; E = { Name = "E", MaxHealth = 200, ExpLimit = 2000, NextRank = "D" }; D = { Name = "D", MaxHealth = 250, ExpLimit = 3000, NextRank = "C" }; C = { Name = "C", MaxHealth = 300, ExpLimit = 4000, NextRank = "B" }; B = { Name = "B", MaxHealth = 400, ExpLimit = 5000, NextRank = "A" }; A = { Name = "A", MaxHealth = 500, ExpLimit = 100000000000, }; }; } return DataProperties;
Can anyone help me with the error is it because of placement, because i already tried changing the position of the function in the script i still retrieved the same error. Thanks for review my script, your help is appreciated.
I was going to talk to you in community chat in this, but I decided I'd make a post because I've gotta go to bed soon. There's a lot going on here.
When did you call upon the function? you used humanoid as a variable before it was defined. Then you define it WAY later in the script. But you defined it locally. That's my issue.
The error is coming up saying that you are associating MaxHealth with nil, and nil just doesn't exist.
Without the whole script there's, not a lot I see myself doing. I did some testings your humanoid is correctly defined, but based on logic, since it was defined on line 206 and not 98 or before 98 that might be the problem.
Try defining humanoid later before line 98.