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
 

Function issue

Previous Thread :: Next Thread 
Skriptten is not online. Skriptten
Joined: 27 Sep 2010
Total Posts: 244
03 Nov 2015 05:53 AM
The issue with my script is that the function is called more than once, is there a way
to make sure it could only be called once?
(Ignore the print statments, they're meant to test the script and tell me where they break)

local player = script.Parent.Parent
local mouse = player:GetMouse()
x = 0
stop = false
mouse.KeyDown:connect (function (run)
if (run == "0") then
if script.Stamina.Value > 20 then
print("running")
script.Run.Value = true
repeat
print(x.. " " ..script.Stamina.Value)
if x < 10 then
x = x + 1
end
script.Stamina.Value = script.Stamina.Value - 1
player.Character.Humanoid.WalkSpeed = 16+x
game.Workspace.Camera.FieldOfView = 70+x
wait(0.01)
until script.Run.Value == false or script.Stamina.Value <= 0
stop()
else
print"No stam :c"
end
end
end)
function stop()
print"Stopping"
script.Run.Value = false
repeat
print(x.. " " ..script.Stamina.Value)
x = x - 1
player.Character.Humanoid.WalkSpeed = 16+x
game.Workspace.Camera.FieldOfView = 70+x
wait()
until x <= 0 or script.Run.Value == true
x = 0
wait(2)
repeat
if script.Stamina.Value < 100 then
script.Stamina.Value = script.Stamina.Value + 1
end
wait(0.5)
until script.Run.Value == true or script.Stamina.Value >= 100
end

mouse.KeyUp:connect (function (letgo)
if (letgo == "0") then
stop()
end
end)
Report Abuse
Skriptten is not online. Skriptten
Joined: 27 Sep 2010
Total Posts: 244
03 Nov 2015 05:55 AM
For clarification, when the user spams Left Shift the stam regen is multiplied by the times they've pressed left shift.
Report Abuse
scottmike0 is not online. scottmike0
Joined: 14 Sep 2008
Total Posts: 1073
03 Nov 2015 05:58 AM
well, you called 2 different mouse functions.. i know from recent experience you cannot call mouse:connect more than once, at least when dealing with clicking, so therefore it also must affect for buttons pressed as well.
Report Abuse
Skriptten is not online. Skriptten
Joined: 27 Sep 2010
Total Posts: 244
03 Nov 2015 06:01 AM
Scott, you're right! :D
Except one problem, how do I stop now? Lol

mouse.KeyUp:connect (function (letgo) -- Stops running, pretty important
if (letgo == "0") then
stop()
end
end)
Report Abuse
Skriptten is not online. Skriptten
Joined: 27 Sep 2010
Total Posts: 244
03 Nov 2015 06:03 AM
Nvm, it still does the same thing when I spam left shift :p
Report Abuse
scottmike0 is not online. scottmike0
Joined: 14 Sep 2008
Total Posts: 1073
03 Nov 2015 06:12 AM
change letgo to an actual function and call it in the first function.
Report Abuse
Skriptten is not online. Skriptten
Joined: 27 Sep 2010
Total Posts: 244
03 Nov 2015 06:34 AM
Well I tried something... similar and got interesting results xD
When I ran this my screen shook as if my character was at a Friday night frat party

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
x = 0
stop = false
mouse.KeyDown:connect (function (run)
if (run == "0") then
if script.Stamina.Value > 20 then
print("running")
script.Run.Value = true
repeat
print(x.. " " ..script.Stamina.Value)
if x < 10 then
x = x + 1
end
script.Stamina.Value = script.Stamina.Value - 1
player.Character.Humanoid.WalkSpeed = 16+x
game.Workspace.Camera.FieldOfView = 70+x
wait(0.01)
mouse.KeyUp:connect (function (letgo)
if (letgo == "0") then
stop()
end
end)
until run == false or script.Stamina.Value <= 0
stop()
else
print"No stam :c"
end
end
end)
function stop()
print"Stopping"
script.Run.Value = false
repeat
print(x.. " " ..script.Stamina.Value)
if x < 0 then
break
end
x = x - 1
player.Character.Humanoid.WalkSpeed = 16+x
game.Workspace.Camera.FieldOfView = 70+x
wait()
until x <= 0 or script.Run.Value
x = 0
wait(2)
repeat
if script.Stamina.Value < 100 then
script.Stamina.Value = script.Stamina.Value + 1
end
wait(0.5)
until script.Run.Value or script.Stamina.Value >= 100
end
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
03 Nov 2015 08:17 AM
UIS
Report Abuse
robocu3 is not online. robocu3
Joined: 13 Mar 2009
Total Posts: 6485
03 Nov 2015 08:18 AM
^

-=Robo=-
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