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.

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

Then I got this function in a module script.

01Module = {}
02 
03 
04function Module.Will_IEatApples(DoILikeApples)
05    while DoILikeApples ~= true then
06        wait(1)
07        if DoILikeApples == false then
08            print("No")
09        else
10            print("yes")
11        end
12    end
13end
14 
15 
16return Module

then back in my script, I add this.

01local Module = require(game.serverscriptservice.Module)
02 
03local DoILikeApples = false
04 
05 
06Module.Will_IEatApples(DoILikeApples)
07 
08wait(5)
09 
10DoILikeApples = 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...

1local BoolValue = workspace.DoILikeApples
2 
3BoolValue.Changed:Connect(function()
4    if BoolValue.Value == true then
5      print("I like apples now!")
6    else
7      print("I don't like apples now!")
8    end
9end)
Ad

Answer this question