I was scripting a scrap collect and sell system for my friend today until I became stumped at a error.
It said: "Workspace.Demo.Trash & Scrap.Barrel.ProximityPrompt.ScrapScript:20: attempt to index nil with ‘Value’.
Heres the code and the line where it had a problem with highlighted.
Problem 1:
You’re checking if PlayerScrapValue
exists, and if it does, then it makes a new value. You should only be doing it if it doesn’t exist.
Problem 2:
If the player doesn’t have the ScrapValue
, the value would be nil
. That’s why it’s erroring.
You should check if it doesn’t exist, and if it doesn’t, set the Amount to Scrap.Value
.
Thanks so much, now I realize I just had to change line 15 to Scrap.Value = 0 + ScrapAmountValue
and line 11 to if PlayerScrapValue == nil then
and remove lines 17 & 18. Have a good day!
1 Like