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
 

Re: Scripts not interacting with same value or something..?

Previous Thread :: Next Thread 
zub74 is not online. zub74
Joined: 13 Sep 2008
Total Posts: 489
05 Jun 2014 04:08 PM
So 2 values, rate and cash. Rate is 1, cash starts at 0

rate=workspace.Rate.Value

cash=workspace.Cash.Value

while true do
wait(1)
print(cash)
if rate>0 then
wait(1)
cash=cash+rate
end
end

I have another script that waits 3 seconds then changes the rate to another number. The first script doesn't recognize the change/ continues as if the rate was still 1. Why?
Report Abuse
sonicdiablo is not online. sonicdiablo
Joined: 05 Feb 2009
Total Posts: 1661
05 Jun 2014 04:10 PM
Because you're not changing the values of the variables.They don't change dynamically like that.
Report Abuse
zub74 is not online. zub74
Joined: 13 Sep 2008
Total Posts: 489
05 Jun 2014 04:11 PM
How would I detect a change, then?
Report Abuse
sonicdiablo is not online. sonicdiablo
Joined: 05 Feb 2009
Total Posts: 1661
05 Jun 2014 04:13 PM
Add the variables inside the loop.This way the value will get changed everytimes that loop is executed.
Report Abuse
nomer888 is not online. nomer888
Joined: 13 Feb 2010
Total Posts: 551
05 Jun 2014 04:13 PM
Put the variable declarations in the while loop.
Report Abuse
zub74 is not online. zub74
Joined: 13 Sep 2008
Total Posts: 489
05 Jun 2014 04:19 PM
I can't get it to work. I've tried like 5 different configurations or so.
Could you write it out?
Report Abuse
nomer888 is not online. nomer888
Joined: 13 Feb 2010
Total Posts: 551
05 Jun 2014 04:21 PM
while wait(1) do
rate=workspace.Rate.Value
cash=workspace.Cash.Value
print(cash)
if rate>0 then
wait(1)
cash=cash+rate
end
end
Report Abuse
vlekje513 is not online. vlekje513
Joined: 28 Dec 2010
Total Posts: 9057
05 Jun 2014 04:24 PM

while wait(1) do
rate=workspace.Rate

cash=workspace.Cash
print(cash.Value)
if rate.Value>0 then
wait(1)
cash.Value=cash.Value+rate.Value
end
end
Report Abuse
nomer888 is not online. nomer888
Joined: 13 Feb 2010
Total Posts: 551
05 Jun 2014 04:27 PM
Whoops. Vlek's got it right.
Report Abuse
zub74 is not online. zub74
Joined: 13 Sep 2008
Total Posts: 489
05 Jun 2014 04:28 PM
Both of your scripts didn't work, for some reason. Fixed it, though. The print needs to be in the if then statement. I also changed it to while true do.
while true do
rate=workspace.Rate.Value
cash=workspace.Cash.Value
if rate>0 then
wait(1)
cash=cash+rate
print(cash)
end
end
Report Abuse
nomer888 is not online. nomer888
Joined: 13 Feb 2010
Total Posts: 551
05 Jun 2014 04:45 PM
I wouldn't advise that - every time the rate is 0, the while loop freezes your game until it isn't 0.
Report Abuse
zub74 is not online. zub74
Joined: 13 Sep 2008
Total Posts: 489
05 Jun 2014 04:47 PM
What if I just put else end?
Report Abuse
nomer888 is not online. nomer888
Joined: 13 Feb 2010
Total Posts: 551
05 Jun 2014 04:50 PM
You have to yield a loop unless you want everything to run all at once, which usually freezes your game. While wait() do is a good way to avoid anything wrong happening, it's clean, and compact. Else end doesn't do anything.
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