Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Attempt to Index nil with..?

Asked by 3 years ago
Edited 3 years ago

So I am trying to make a Leveling System. To gain EXP, you must touch a block. The script is within the Part that needs to be touched. Now, I am getting an error that says ' attempt to index nil with 'LevelsInfo'' The problem is, the script isn't able to find the LevelsInfo which is a Fold with String Values within the Player. I know that I will more than likely have to use a Local Script for this, but why won't it work with a Local Script. If it is possible though to use a normal Script, how would I go about doing that. This is the line that it gets into trouble at 'player.LevelsInfo.Experience.Value += expToGain' Thanks in the long run! -XRangerGuyX


local part = script.Parent local debounce = false`` part.Touched:Connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if not debounce then debounce = true local playersFinished = 0 wait(3) if playersFinished == 0 then print("A Player Has Finished!") local expToGain = 3 playersFinished += 1 player.LevelsInfo.Experience.Value += expToGain elseif playersFinished >= 2 then print("A 2nd Player Has Finished!") local expToGain = 1 player.LevelsInfo.Experience.Value += expToGain end wait(1) debounce = false end end)

1 answer

Log in to vote
0
Answered by 3 years ago

Maybe try

player:FindFirstChild("LevelsInfo"):FindFirstChild("Experience").Value +=expToGain

?

0
attempt to index nil with 'FindFirstChild' is what comes up.. XRangerGuyX 29 — 3y
0
Then you dont even have a folder GiantDefender427 0 — 3y
0
No.. I definitely do.. XRangerGuyX 29 — 3y
0
There's no reason to use FindFirstChild if you're not going to check to see if it returns nil. The error with indexing nil with 'FindFirstChild' definitely means that either 'player' is nil or that the 'LevelsInfo' folder either isn't actually named 'LevelsInfo' or hasn't been created (yet). You can use print statements to figure out which, ex: print(player, player and player:FindFirstChild("Level chess123mate 5873 — 3y
Ad

Answer this question