I was making a game from a tutorial and I copied and checked everything exactly as it should have been. However, when I played the game, this error message appeared:
01 | ServerScriptService.Script: 17 : attempt to index nil with 'Value' |
02 |
03 | It said that the problem was this line: |
04 | return game.ServerStorage.Cars:FindFirstChild(NameOfCar.Price.Value) |
05 | This is the code that was inside the script. |
06 | Does anyone know how to fix this? |
07 |
08 |
09 | game.Players.PlayerAdded:Connect( function (plr) |
10 | local leaderstats = Instance.new( "Folder" ) |
11 | local folder = leaderstats |
12 | leaderstats.Name = "leaderstats" |
13 | leaderstats.Parent = plr |
14 | local cash = Instance.new( "IntValue" ) |
15 | cash.Name = "Cash" |
When you code NameOfCar.Price.Value
, you are indexing NameOfCar to find Price, and then Price to find value. However, the error say you are attempting to index a Nil value with Value
, which would indicate that Price
is nil.
I suspect, however, that what you meant to write was:
1 | return game.ServerStorage.Cars:FindFirstChild(NameOfCar).Price.Value |
The error resulted from you Indexing NameOfCar.Price, which does not exist because NameOfCar is a string. You have to close the parentheses on FindFirstChild, so that the function can find the Car model, which is what contains the Price variable.