I have this script that when the thing is eaten, a health bar goes down.
I get this error
22:12:17.349 - Workspace.Water2.WaterScript:25: attempt to perform arithmetic on global 'currentthirst' (a nil value)
This is the script:
local Tool = script.Parent;
local enabled = false
function onActivated()
enabled = false
Tool.GripForward = Vector3.new(0,-.759,-.651)
Tool.GripPos = Vector3.new(1.5,-.5,.3)
Tool.GripRight = Vector3.new(1,0,0)
Tool.GripUp = Vector3.new(0,.651,-.759)
Tool.Handle.DrinkSound:Play()
script.Parent.Bites.Value = script.Parent.Bites.Value + 1
Eable()
delay(3,function()
local character = Tool.Parent
local player = game.Players:GetPlayerFromCharacter( character )
thirst = player.PlayerGui.Thirst
maxthirst = 100 --create a max thirst value
currentthirst = 100 --create a currentthirst value
local currentthirstpercent = currentthirst/maxthirst
end)
end
function updatebar()
local currentthirstpercent = currentthirst/maxthirst --re-divides the thirst values
thirst.BG.Bar.Size = UDim2.new(currentthirstpercent,0,1,0) --sets the size in the x of the bar to the percentage of thirst remaining
end
function drink() --example function for increasing thirst
currentthirst = currentthirst + -50 --add thirst together
if currentthirst > maxthirst then --checks to see you aren't over the max
currentthirst = maxthirst --if you're over the max it sets you to the max
end
end
updatebar() --updates the bar because you changed the value of thirst
Tool.GripForward = Vector3.new(-.976,0,-0.217)
Tool.GripPos = Vector3.new(0.03,0,0)
Tool.GripRight = Vector3.new(.217,0,-.976)
Tool.GripUp = Vector3.new(0,1,0)
enabled = true
function onEquipped()
Tool.Handle.OpenSound:play()
end
function Eable()
if (script.Parent.Bites.Value) > 5 then
script.Parent:Remove()
end
end
script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)

2 comments
Isn't it defined in line 18?
line 18 is inside the scope of a function. For it to be defined you would have to have called the function as a prerequisite for line 25 to not break your code.