Error "attempt to call a nil value"

I want to make a function that when it is called, it plays a tween. I got an error that says “attempt to call a nil value” and couldn’t find a fix. Does anyone know how to fix it?

The script is a script for backpacks in simulators. Where currentBlocks is collected and maxBlocksValue is how much the backpack can hold.(They are both IntValues)

currentBlocks:GetPropertyChangedSignal(“Value”):Connect(tw)

if currentBlocks.Value >= maxBlocksValue.Value then
tw() -------------------------------------------------------------------This is where I get the error
end

function tw()
if currentBlocks.Value >= maxBlocksValue.Value then
gui.Visible = true
print(“a”)

  local TS = game:GetService("TweenService")
  local Info = TweenInfo.new(
  	2,
  	Enum.EasingStyle.Cubic,
  	Enum.EasingDirection.InOut,
  	-1,
  	true,
  	0
  )
  local tween = TS:Create(gui.Arrow, Info, {Position = UDim2.new(-0.666, 0,-0.283, 0)})
  while wait() do
  	tween:Play()
  	tween.Completed:Wait()
  	if gui.Visible == false then
  		break
  	end
  end

end
end

Can i see the script? Makes it easier to deduce what the issue is

Are you expecting me to read your thoughts :disappointed_relieved::disappointed_relieved::disappointed_relieved::disappointed_relieved:

You should provide the script you tested so we can actually help

@ObviouslyGreen
@FriezaShouldHaveWon
I edited the post. The script should be on it right now.

You should define the tw function before you try to call it, so move it higher than the tw(). Probably at the very top of your script somewhere.

Thanks! But I’m confused why wouldn’t it work the original way I tried it?

Because you’d be calling a function that doesn’t exist yet. You have to make sure the function exists before you try to call it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.