Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i let my a function in my module know that a variable in another script has been changed?

Say I got a script right.


local Module = require(game.serverscriptservice.Module) 
local DoILikeApples = false


Then I got this function in a module script.

Module = {}


function Module.Will_IEatApples(DoILikeApples)
	while DoILikeApples ~= true then
		wait(1)
		if DoILikeApples == false then
			print("No")
		else
			print("yes")
		end
	end
end


return Module 

then back in my script, I add this.

local Module = require(game.serverscriptservice.Module) 

local DoILikeApples = false


Module.Will_IEatApples(DoILikeApples)

wait(5)

DoILikeApples = true

how do I communicate with my module function to let it know the new value for DoILikeApples

1 answer

✓ Accepted answer

As explained in the web chat...

local BoolValue = workspace.DoILikeApples

BoolValue.Changed:Connect(function()
    if BoolValue.Value == true then
      print("I like apples now!")
    else
      print("I don't like apples now!")
    end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.