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 » Scripters
Home Search
 

Re: Why is this loop not working?

Previous Thread :: Next Thread 
Skenderbeu98 is not online. Skenderbeu98
Joined: 11 Aug 2013
Total Posts: 467
13 May 2015 07:52 PM
So basically this code is supposed to constantly make the int value of the player's smithing xp the value of the intvalue inside the textbutton (inside the first loop) and the second loop which is the one that doesn't work it supposed to check the player's smithing xp stat and if it's value is greater than 99, make the xp equal to 0 and add one value to the smithing int value of the player. I tried making this all one loop, I've tried everything, either it's buggy like adds 2 levels instead of one or doesn't work. Any help?

local db = false
while wait() do
if not db then
db = true
wait()
local player = script.Parent.Parent.Parent.Parent
local xrp = script.Parent.xp.Value
script.Parent.xp.Value = player.Stats.Smithing.xp.Value
script.Parent.Text = "Xp: ".. xrp

db = false
end
end


while wait() do
wait()
local player = script.Parent.Parent.Parent.Parent

if player.Stats.Smithing.xp.Value >= 100 then
player.Stats.Smithing.Value = player.Stats.Smithing.Value + 1
wait()
player.Stats.Smithing.xp.Value = 0
wait(.05)
end
end
Report Abuse
theninjaguy987 is not online. theninjaguy987
Joined: 21 Jun 2013
Total Posts: 766
13 May 2015 07:57 PM
Where is this located, and what type of script is it?
Report Abuse
Skenderbeu98 is not online. Skenderbeu98
Joined: 11 Aug 2013
Total Posts: 467
13 May 2015 08:00 PM
So basically location is
Player > PlayerGui > ScreenGui > exp (Textbutton) > script
regular script not local
Report Abuse
GeoVolcano is not online. GeoVolcano
Joined: 05 Jul 2012
Total Posts: 1433
13 May 2015 08:04 PM
I would do something like this as I'd assume you would later increase the area of xp range. That way it would be harder to achieve new levels.

local determiningfactor = 5 -- Rate of growth
if xp.Value >= (Smithing.Value * determiningfactor) then
xp.Value = xp.Value - (Smithing.Value * determiningfactor)
Smithing.Value = Smithing.Value + 1
end
Report Abuse
Skenderbeu98 is not online. Skenderbeu98
Joined: 11 Aug 2013
Total Posts: 467
14 May 2015 02:13 PM
The second loop won't work though
Report Abuse
robotmega is not online. robotmega
Joined: 16 May 2009
Total Posts: 14084
14 May 2015 02:15 PM
local db = false
local player = script.Parent.Parent.Parent.Parent
local xrp = script.Parent.xp.Value
while wait() do
if not db then
db = true
wait()
script.Parent.xp.Value = player.Stats.Smithing.xp.Value
script.Parent.Text = "Xp: ".. xrp
db = false
end
end

spawn(function()
while wait() do
wait()
if player.Stats.Smithing.xp.Value >= 100 then
player.Stats.Smithing.Value = player.Stats.Smithing.Value + 1
wait()
player.Stats.Smithing.xp.Value = 0
wait(.05)
end
end
end)
Report Abuse
robotmega is not online. robotmega
Joined: 16 May 2009
Total Posts: 14084
14 May 2015 02:15 PM
oops



local db = false
local player = script.Parent.Parent.Parent.Parent
local xrp = script.Parent.xp.Value

spawn(function()
while wait() do
if not db then
db = true
wait()
script.Parent.xp.Value = player.Stats.Smithing.xp.Value
script.Parent.Text = "Xp: ".. xrp
db = false
end
end
end)

while wait() do
wait()
if player.Stats.Smithing.xp.Value >= 100 then
player.Stats.Smithing.Value = player.Stats.Smithing.Value + 1
wait()
player.Stats.Smithing.xp.Value = 0
wait(.05)
end
end

Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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