Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
abrobot 44
4 years ago
Edited 4 years ago

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

Log in to vote
1
Answered by 4 years ago

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)
Ad

Answer this question