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: Three Tier Running Script [Help Needed]

Previous Thread :: Next Thread 
Wizzoblox02 is online. Wizzoblox02
Joined: 29 Dec 2015
Total Posts: 101
31 Dec 2016 03:45 PM
So my friend and I are making a level and I decided to make a three tier running script which is basically as following: Walking -> Running -> Sprinting -> Walking, etc..

The issue is that the three functions I use all go at once causing it to error going as follows: Walking -> Running -> Sprinting -> Running (It goes to Walking but instantly to Running)

----------------------------------Beginning of Script-----------------------------------

uis = game:GetService("UserInputService")
plr = game.Players.LocalPlayer
char = game.Workspace:WaitForChild(plr.Name)
human = char.Humanoid
walk = 16
run = 30
sprint = 50

uis.InputBegan:connect(function(Walk)
if Walk.KeyCode == Enum.KeyCode.LeftShift then
if human.WalkSpeed == walk then
human.WalkSpeed = run
print("Jogging Enabled")
end
end
end)


uis.InputBegan:connect(function(Run)
if Run.KeyCode == Enum.KeyCode.LeftShift then
if human.WalkSpeed == run then
human.WalkSpeed = sprint
print("Sprinting Enabled")
end
end
end)

uis.InputBegan:connect(function(Sprint)
if Sprint.KeyCode == Enum.KeyCode.LeftShift then
if human.WalkSpeed == sprint then
human.WalkSpeed = walk
print("Walking Enabled")
end
end
end)

----------------------------------------End of Script-----------------------------------
Report Abuse
UltimateRaheem is not online. UltimateRaheem
Joined: 10 Nov 2012
Total Posts: 1886
31 Dec 2016 04:46 PM
All of your functions check if it is left shift. I'll fix it for ya. Holding onto nothing makes the character walk. Holding onto left shift makes the character sprint. Holding onto LeftControl makes the character run. You don't need that many events, just 1. But it cba to fix it.

uis = game:GetService("UserInputService")
plr = game.Players.LocalPlayer
char = plr.Character
human = char:WaitForChild("Humanoid")
walk = 16
run = 30
sprint = 50

uis.InputBegan:connect(function(walk)
if walk.KeyCode != Enum.KeyCode.LeftShift or Enum.KeyCode.LeftControl then
human.WalkSpeed = walk
print("Jogging Enabled")
end
end)


uis.InputBegan:connect(function(sprint)
if sprint.KeyCode == Enum.KeyCode.LeftShift then
human.WalkSpeed = sprint
print("Sprinting Enabled")
end
end)

uis.InputBegan:connect(function(run)
if run.KeyCode == Enum.KeyCode.LeftControl then
human.WalkSpeed = run
print("Running")
end
end)


http://wiki.roblox.com
Report Abuse
Wizzoblox02 is online. Wizzoblox02
Joined: 29 Dec 2015
Total Posts: 101
31 Dec 2016 05:18 PM
I should also mention this script is in the starterpack, and that your script didn't work. I also played this game that where if you pressed shift once you went faster, then press it again, you went faster, press it again you were at default. This is what I'm aiming for but your script involved more than 1 key and only immobilized my character
Report Abuse
freya02 is not online. freya02
Joined: 04 Dec 2013
Total Posts: 272
02 Jan 2017 03:44 AM
-------------------code---------------------------

uis = game:GetService("UserInputService")
plr = game.Players.LocalPlayer
char = game.Workspace:WaitForChild(plr.Name)
human = char.Humanoid
walk = 16
run = 30
sprint = 50
running = false

pcall(coroutine.resume(coroutine.create(function()
while true do
wait()
if running == true then
human.WalkSpeed = run
if uis:IsKeyDown(Enum.KeyCode.LeftShift) == false then
running = false
isInit = false
human.WalkSpeed = walk
end
end
end
end)))
isInit = false
function initRun()
if uis:IsKeyDown(Enum.KeyCode.LeftShift) then
human.WalkSpeed = walk
print 'walk'
else
human.WalkSpeed = walk
isInit = false
return
end
wait(1)
if uis:IsKeyDown(Enum.KeyCode.LeftShift) then
human.WalkSpeed = run
print 'run'
else
human.WalkSpeed = walk
isInit = false
return
end
wait(1)
if uis:IsKeyDown(Enum.KeyCode.LeftShift) then
human.WalkSpeed = sprint
print 'sprint'
else
human.WalkSpeed = walk
isInit = false
return
end
wait(1)
print 'running'
running = true
end

while true do
wait()
if char then
if uis:IsKeyDown(Enum.KeyCode.LeftShift) and isInit == false then
isInit = true
initRun()
end
end
end

-------------------code---------------------------

Here you go, soz if i wrote too much lmao, but it handle all cases, it won't stop running if you keep pressing shift and it won't crash if we don't press shift while the character is in the sprinting period.


Report Abuse
freya02 is not online. freya02
Joined: 04 Dec 2013
Total Posts: 272
02 Jan 2017 03:44 AM
Make sure to put the script in a LocalScript !!


Report Abuse
Wizzoblox02 is online. Wizzoblox02
Joined: 29 Dec 2015
Total Posts: 101
02 Jan 2017 12:22 PM
It seems people aren't getting the point. I'm trying to make it so you DON'T have to hold DOWN the shift button. Just press it to increase speed. I've also created a new script that I think should work, but I just have to figure out how to make the script stop the code and start over. where I left a space in.

------------------------------------Beginning of Script-----------------------------------

uis = game:GetService("UserInputService")
plr = game.Players.LocalPlayer
char = game.Workspace:WaitForChild(plr.Name)
Script = script.Parent.Speed
human = char.Humanoid
walk = 16
run = 30
sprint = 50

uis.InputBegan:connect(function(Walk)
if Walk.KeyCode == Enum.KeyCode.LeftShift then
if human.WalkSpeed == walk then
human.WalkSpeed = run
print("Running Enabled")

if human.WalkSpeed == run then
human.WalkSpeed = sprint
print("Sprinting Enabled")

if human.WalkSpeed == sprint then
human.WalkSpeed = walk
print("Walking Enabled")

end
end
end
end
end)

-------------------------------------End of Script--------------------------------------
Report Abuse
freya02 is not online. freya02
Joined: 04 Dec 2013
Total Posts: 272
03 Jan 2017 12:46 PM
uis = game:GetService("UserInputService")
plr = game.Players.LocalPlayer
char = game.Workspace:WaitForChild(plr.Name)
human = char.Humanoid
walk = 16
run = 30
sprint = 50

uis.InputBegan:connect(function(Walk)
if Walk.KeyCode == Enum.KeyCode.LeftShift then
if human.WalkSpeed == walk then
human.WalkSpeed = run
print("Running Enabled")
elseif human.WalkSpeed == run then
human.WalkSpeed = sprint
print("Sprinting Enabled")

elseif human.WalkSpeed == sprint then
human.WalkSpeed = walk
print("Walking Enabled")
end
end
end)

---------------
There you go, it works.


Report Abuse
UltimateRaheem is not online. UltimateRaheem
Joined: 10 Nov 2012
Total Posts: 1886
03 Jan 2017 12:48 PM
^ Idk if it works or not but thanks for only making 1 input began function, because I really couldn't be asked to cut all those functions xD


http://wiki.roblox.com
Report Abuse
Wizzoblox02 is online. Wizzoblox02
Joined: 29 Dec 2015
Total Posts: 101
03 Jan 2017 04:57 PM
That's probably because I tried making a new one with only 1 input began function. So ima about to go test it out and hopefully it works. If so thank you so much to @freya02
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