any explanation?
local clickdetect = script.Parent:WaitForChild("ClickDetector") clickdetect.MouseClick:Connect(function(plr) print(plr) local Thirst = plr:FindFirstChild("ThirstVal") if Thirst.Value >100 then Thirst.Value = 100 end Thirst.Value = 100 end)
Workspace.Land.Model.Detector.Script:6: attempt to index local 'Thirst' (a nil value)?
This means that Thirst
is nil
. You can't index something that is nil since that makes no sense.
local a = nil print(a.b)
This will output an error attempt to index local 'a' (a nil value)
since a
is nil
and not a table
or a userdata
or has no metatable with a __index
set.
Think about what your code is doing. You're looking for something called ThirstVal
specifically inside plr
. Perhaps you have it in a specific folder, or its inside their Character
. To index a player's character use the .Character
property. (plr.Character
)
To prevent this error for now you can check if Thirst
even exists in the first place using an if statement.
local clickDetect = ... local function clicked(player) print(player) local thirst = player:FindFirstChild("ThirstVal") if thirst then --// make sure it actually exists --// logic checks for else --// warn it doesn't exist and print the reference point to your player. warn("no thirst value inside of: " .. player:GetFullName()) end end clickDetect.MouseClick:Connect(clicked)
Though again, I do suggest making sure you check where the ThirstVal
is actually being added. Perhaps try indexing the player's character and looking for it.