generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

How to continuously check a variable?

Previous Thread :: Next Thread 
Roryo is not online. Roryo
Joined: 05 Jun 2008
Total Posts: 113
17 Aug 2013 12:56 PM
I'm writing a script for a display that reads out the value of a local variable, but I can't get the script to continuously check the variable using if statements, even in a while loop. I'd be very grateful if someone could help me here, because I have no idea.
Report Abuse
Absurdism is not online. Absurdism
Joined: 18 Jul 2013
Total Posts: 2568
17 Aug 2013 12:59 PM
Yes you can.

x = 5
while (wait()) do
assert((x == 5), 'x is no longer 5.')
end
Report Abuse
Hibobb is not online. Hibobb
Joined: 18 Apr 2010
Total Posts: 2146
17 Aug 2013 01:01 PM
Try defining the variable in the while loop. For example;

while wait(1) do
local value = Workspace.IntValue
local msg = Instance.new("Hint",Workspace)
msg.Text = "The IntValue equals"..value.Value..""
wait(2)
msg:Remove()
end

This way, it will redefine value each time
Report Abuse
Roryo is not online. Roryo
Joined: 05 Jun 2008
Total Posts: 113
17 Aug 2013 01:13 PM
Neither of these worked for me.
Report Abuse
MeBilly8440 is not online. MeBilly8440
Joined: 27 Jul 2009
Total Posts: 2783
17 Aug 2013 01:15 PM
Is your problem that you need to run things after your while loop? If so, just say so. If not, here's what I'd do:

-- Let's just say that the variable you need is "var"
local var2 = var -- This is what we will use to determine if it's changed or not... never change var2
while (wait()) do
if (var ~= var2) then
print("Var changed") -- You can do something here
end
end

Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson
Report Abuse
Roryo is not online. Roryo
Joined: 05 Jun 2008
Total Posts: 113
17 Aug 2013 01:20 PM
I'm actually looking to check a local variable which points to the value of a NumberValue in the workspace, and respond to what its value is with if statements which are inside the loop. However, it only updates the first time, and when the value changes, the script doesn't do anything.
Report Abuse
MeBilly8440 is not online. MeBilly8440
Joined: 27 Jul 2009
Total Posts: 2783
17 Aug 2013 01:22 PM
Ahhh, okay! Here's what you'd do:

value.Changed:connect(function(thing) -- value being your NumberValue object in Workspace.
if (thing == "Value") then
-- The value changed, you can do something here
end
end)

Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson
Report Abuse
Hibobb is not online. Hibobb
Joined: 18 Apr 2010
Total Posts: 2146
17 Aug 2013 01:38 PM
^Make sure to define value
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image