Variable not returning

am doing soemthing wrong but idk what it is

-script

Drink.Equipped:Connect(function()
	print("SET OFF")
	equipping = true
	ToolHandler.Equip(Drink, 1, equipping)
	
	
end)

-module

function ToolHandlerModule.Equip(Item, EquipTime, Equipping)
	
	task.wait(EquipTime)
	Equipping = false
	print("returned")
	return Equipping
	
end

equipping isnt returning as false

1 Like

What is equipping, is it a BoolValue object or a local variable?
If it is a BoolValue, you must access it directly in the module (through drink or location of the BoolValue)
If it is a local variable, you can do this to set it back to false:

equipping = ToolHandler.Equip(Drink, 1, equipping

The reason for this is it passes to the module a copy of the object, not the object itself

2 Likes

You seem to have a slight misunderstanding of how scopes work. The equipping variable in the first codeblock, is not actually the same variable as Equipping in the second codeblock. When you call the function and pass the equipping variable, a new variable is created within the function scope, so changing the Equipping variable does not affect the equipping variable. returning a variable also does not affect this, you can however achieve what you are trying to do by returning the variable. See @neweve2323’s response for adjustments you need to make for that.

Hope this helps!

1 Like

Th naks
it was a locla vairbale

1 Like

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