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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| Joined: 16 Jul 2011 |
| Total Posts: 832 |
|
| |
|
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
|
  |
| Joined: 16 Jul 2011 |
| Total Posts: 832 |
|
| |
|
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
|
  |
| 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 |
|
|
|
| 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
|
  |
| Joined: 16 Jul 2011 |
| Total Posts: 832 |
|
| |
|
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
|
  |
| 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
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 285 |
|
|
| 14 Feb 2015 10:15 AM |
| hmm, what shall i do then lol |
|
|
| Report Abuse |
|
|
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
|
  |
| Joined: 16 Jul 2011 |
| Total Posts: 832 |
|
| |
|
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
|
  |
| Joined: 16 Jul 2011 |
| Total Posts: 832 |
|
|
| 15 Feb 2015 09:32 AM |
| Just put local a = 100 under local up = flase |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 285 |
|
|
| 17 Feb 2015 10:55 AM |
| no problem, thanks for helping out :) |
|
|
| Report Abuse |
|
|