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: How to continuously decrease by 2 from 100?

Previous Thread :: Next Thread 
RoboX790 is not online. RoboX790
Joined: 05 Nov 2009
Total Posts: 285
14 Feb 2015 09:33 AM
hi, im trying to learn basic math on roblox and I can't get this to work. I want 100 to be decreased by 2 continuously. here's a script I made:

while true do
wait(0.1)
game.Players.LocalPlayer.PlayerGui.ActionBar.Main.HealthAndMana.ManaBar.Text = 100 - decrease .. "/100"
end

any idea?
Report Abuse
1ExplodingNoob1 is not online. 1ExplodingNoob1
Joined: 12 Dec 2010
Total Posts: 58
14 Feb 2015 09:38 AM
Use a for loop.

for variableYouWantToDecrease = 100, numberYouWantToEndWith, -2 do
wait(0.1)
print(variableYouWantToDecrease) --[[ Simply waits 100 milliseconds, then prints out the decreased number. ]]
end
Report Abuse
RoboX790 is not online. RoboX790
Joined: 05 Nov 2009
Total Posts: 285
14 Feb 2015 09:42 AM
i tried this

if C.Humanoid.WalkSpeed == 32 then
for a = 100, -2 do
wait(0.1)
game.Players.LocalPlayer.PlayerGui.ActionBar.Main.HealthAndMana.ManaBar.Text = a
end
end

it still decreases to 98.
Report Abuse
1ExplodingNoob1 is not online. 1ExplodingNoob1
Joined: 12 Dec 2010
Total Posts: 58
14 Feb 2015 09:45 AM
Try this:

if C.Humanoid.WalkSpeed == 32 then
for a = 100, 0, -2 do
wait(0.1)
game.Players.LocalPlayer.PlayerGui.ActionBar.Main.HealthAndMana.ManaBar.Text = a
end
end

Should fix the problem.
Report Abuse
RoboX790 is not online. RoboX790
Joined: 05 Nov 2009
Total Posts: 285
14 Feb 2015 09:45 AM
oh wait nevermind i made a small mistake, it works now :D
Report Abuse
parkiet3 is not online. parkiet3
Joined: 16 Jul 2011
Total Posts: 832
14 Feb 2015 09:46 AM
for a = 100, 0, -2
Report Abuse
RoboX790 is not online. RoboX790
Joined: 05 Nov 2009
Total Posts: 285
14 Feb 2015 09:49 AM
there is one problem.

since this is inside a "shift to run" script, whenever i hold shift it decreases only to 98 and then stops. any idea? i can send you the whole script
Report Abuse
parkiet3 is not online. parkiet3
Joined: 16 Jul 2011
Total Posts: 832
14 Feb 2015 09:52 AM
add a coroutine around it
Report Abuse
parkiet3 is not online. parkiet3
Joined: 16 Jul 2011
Total Posts: 832
14 Feb 2015 09:53 AM
coroutine.resume(coroutine.create(function()

--decrease part

end))
Report Abuse
RoboX790 is not online. RoboX790
Joined: 05 Nov 2009
Total Posts: 285
14 Feb 2015 09:57 AM
anyways i made it work to decrease by 2 whenever i hold shift, now only one problem left which is when i stop holding shift, how do i stop the loop?
Report Abuse
AllianceScripter is not online. AllianceScripter
Joined: 02 Feb 2014
Total Posts: 318
14 Feb 2015 10:00 AM
use break

for i = 100,0,-2 do
--code
if i => 0 then
break
wait()
end
Report Abuse
parkiet3 is not online. parkiet3
Joined: 16 Jul 2011
Total Posts: 832
14 Feb 2015 10:04 AM
Pls just add a coroutine
Report Abuse
RoboX790 is not online. RoboX790
Joined: 05 Nov 2009
Total Posts: 285
14 Feb 2015 10:07 AM
that wont work. here's the full script:

local Player = game.Players:GetPlayerFromCharacter(script.Parent)
C = script.Parent
Mouse = Player:GetMouse()
Debounce = false
decrease = 2

Mouse.KeyDown:connect(function(key)
key = string.lower(key)
if string.byte(key) == 48 then
if Debounce == false then
Debounce = true
C.Humanoid.WalkSpeed = 32
for a = 100, 0, -2 do -- loop starts here
wait(0.5)
game.Players.LocalPlayer.PlayerGui.ActionBar.Main.HealthAndMana.ManaBar.Text = a


Mouse.KeyUp:connect(function(key)
key = string.lower(key)
if string.byte(key) == 48 then
if Debounce == true then
Debounce = false
C.Humanoid.WalkSpeed = 16
--how to break the loop over here?
end
end
end)
end
end
end
end)
Report Abuse
parkiet3 is not online. parkiet3
Joined: 16 Jul 2011
Total Posts: 832
14 Feb 2015 10:13 AM
Wow your ends are placed weird, multiple keyup events will be created
Report Abuse
RoboX790 is not online. RoboX790
Joined: 05 Nov 2009
Total Posts: 285
14 Feb 2015 10:15 AM
hmm, what shall i do then lol
Report Abuse
parkiet3 is not online. parkiet3
Joined: 16 Jul 2011
Total Posts: 832
14 Feb 2015 10:17 AM
local Player = game.Players:GetPlayerFromCharacter(script.Parent)
C = script.Parent
Mouse = Player:GetMouse()
Debounce = false
decrease = 2
local up = false

Mouse.KeyDown:connect(function(key)
key = string.lower(key)
if string.byte(key) == 48 then
if Debounce == false then
up = false
Debounce = true
C.Humanoid.WalkSpeed = 32
local a = 100
repeat
wait(0.5)
a = a - decrease
game.Players.LocalPlayer.PlayerGui.ActionBar.Main.HealthAndMana.ManaBar.Text = a
until up = true or a <= 0

end
end
end)


Mouse.KeyUp:connect(function(key)
key = string.lower(key)
if string.byte(key) == 48 then
if Debounce == true then
up = true
Debounce = false
C.Humanoid.WalkSpeed = 16
--how to break the loop over here?
end
end
end)
Report Abuse
parkiet3 is not online. parkiet3
Joined: 16 Jul 2011
Total Posts: 832
14 Feb 2015 10:18 AM
Try the edited one
Report Abuse
RoboX790 is not online. RoboX790
Joined: 05 Nov 2009
Total Posts: 285
15 Feb 2015 06:15 AM
it works totally fine now, the problem is that whenever i click shift it returns to 100. lol how can i make it stay
Report Abuse
parkiet3 is not online. parkiet3
Joined: 16 Jul 2011
Total Posts: 832
15 Feb 2015 09:32 AM
Just put local a = 100 under local up = flase
Report Abuse
Joe11Joe99 is not online. Joe11Joe99
Joined: 22 May 2011
Total Posts: 34458
15 Feb 2015 09:41 AM
local toDecrease = 100
for i=1, 50 do
game.Players.LocalPlayer.PlayerGui.ActionBar.Main.HealthAndMana.ManaBar.Text = toDecrease- 2 .. "/100"
wait()
end
Report Abuse
RoboX790 is not online. RoboX790
Joined: 05 Nov 2009
Total Posts: 285
15 Feb 2015 11:15 AM
it doesn't work, whenever i use shift it decreases but when i try to use it again it resets to 100 again. i want it to stay in that certain value when i release the shift key. should i work with intValues?
Report Abuse
parkiet3 is not online. parkiet3
Joined: 16 Jul 2011
Total Posts: 832
15 Feb 2015 03:19 PM
I have the fealing i got to do everything by myself ugh

local Player = game.Players:GetPlayerFromCharacter(script.Parent)
C = script.Parent
Mouse = Player:GetMouse()
Debounce = false
decrease = 2
local up = false
local a = 100

Mouse.KeyDown:connect(function(key)
key = string.lower(key)
if string.byte(key) == 48 then
if Debounce == false then
up = false
Debounce = true
C.Humanoid.WalkSpeed = 32
repeat
wait(0.5)
a = a - decrease
game.Players.LocalPlayer.PlayerGui.ActionBar.Main.HealthAndMana.ManaBar.Text = a
until up = true or a <= 0

end
end
end)


Mouse.KeyUp:connect(function(key)
key = string.lower(key)
if string.byte(key) == 48 then
if Debounce == true then
up = true
Debounce = false
C.Humanoid.WalkSpeed = 16
--how to break the loop over here?
end
end
end)
Report Abuse
RoboX790 is not online. RoboX790
Joined: 05 Nov 2009
Total Posts: 285
16 Feb 2015 12:50 PM
no not really you asked me to add local a = 100 so i did but it didnt work, so i got confused. but hey, anyway, thanks for the heaps of help! ill never forget it!
Report Abuse
parkiet3 is not online. parkiet3
Joined: 16 Jul 2011
Total Posts: 832
16 Feb 2015 03:37 PM
Oh np ill be clearer then sry my mistake
Report Abuse
RoboX790 is not online. RoboX790
Joined: 05 Nov 2009
Total Posts: 285
17 Feb 2015 10:55 AM
no problem, thanks for helping out :)
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