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 » Scripting Helpers
Home Search
 

Re: sprinting key help!

Previous Thread :: Next Thread 
Henderick is not online. Henderick
Joined: 10 Dec 2007
Total Posts: 1523
01 May 2013 06:18 PM
I am trying to create a keyboard shortcut where if key "w" AND "shift" are pressed at the same time, a sprinting animation plays along with a decreasing field of view among other things. The character is essentially sprinting.

When "shift" is lifted, the character should return to a regular walk speed, no sprint animation, normal FOV, etc.

However, what ends up happening is that holding down "w" while pressing "shift" does nothing. So obviously letting go of "shift" would not do anything either.

I suspect that there is a certain name, case, or ID for the key "shift". However, it may just be that my script is faulty.

There is no output.

Thank you in advance!!
================================================================

local sprinting = false --Whether or not the character is sprinting.

function KeysDown(key)
if key == "w" then
if key == "shift" then
sprinting = true
[more contents not mentioned]
end

function KeysUp(key)
if key == "shift" then
if sprinting == true then
sprinting = false
[more contents not mentioned]
end
end

Report Abuse
Henderick is not online. Henderick
Joined: 10 Dec 2007
Total Posts: 1523
01 May 2013 06:19 PM
I forgot to write an "end" in the first section of the script, but that wasn't the problem.
Report Abuse
Henderick is not online. Henderick
Joined: 10 Dec 2007
Total Posts: 1523
01 May 2013 06:25 PM
bump?
Report Abuse
emporerj is not online. emporerj
Joined: 23 Nov 2010
Total Posts: 39351
01 May 2013 06:26 PM
You can't say "shift" you have to use the sshift key's id

I think the two shifts are 48 and 49 but I'm not sure.
Report Abuse
Henderick is not online. Henderick
Joined: 10 Dec 2007
Total Posts: 1523
01 May 2013 06:31 PM
How would I incorporate their IDs?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
01 May 2013 06:32 PM
key:byte() == 47
I THINK
Report Abuse
Henderick is not online. Henderick
Joined: 10 Dec 2007
Total Posts: 1523
01 May 2013 06:34 PM
Unfortunately that did not work :/.
Report Abuse
Henderick is not online. Henderick
Joined: 10 Dec 2007
Total Posts: 1523
01 May 2013 06:40 PM
bump x2 :x
Report Abuse
ScrewDeath is not online. ScrewDeath
Joined: 03 Jun 2012
Total Posts: 2700
01 May 2013 06:43 PM
Maybe something like this?

local sprinting = false

function KeysDown(key)
if key:byte() == 119 then--w
mouse.KeyDown:connect(function(x)--define mouse though
if x:byte() == 48 then--shift
--stuff
end)
end
Report Abuse
KilITheClones is not online. KilITheClones
Joined: 19 Mar 2013
Total Posts: 665
01 May 2013 07:02 PM
I have a sprinting script in Kill The Clones which allows you to Double Tap 'w' or forward to make you sprint:
local last = 0

local running = false

local speedboost = 2.2 --times

local mouse = game.Players.LocalPlayer:GetMouse()

function run()
running = true
coroutine.resume(coroutine.create(function()
for i = 1, 3 do
wait()
Workspace.CurrentCamera.FieldOfView = 60+(i*(20/3))
end
end))
if game.Players.LocalPlayer.Character ~= nil then
if game.Players.LocalPlayer.Character:FindFirstChild("Humanoid") ~= nil then
if game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed > (16*(speednote.Value+1))*speedboost-0.1 then
return
end
game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed * speedboost
end
end
end

function walk()
running = false
coroutine.resume(coroutine.create(function()
for i = 1, 3 do
wait()
Workspace.CurrentCamera.FieldOfView = 80-(i*(20/3))
end
end))
if game.Players.LocalPlayer.Character ~= nil then
if game.Players.LocalPlayer.Character:FindFirstChild("Humanoid") ~= nil then
game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed / speedboost
end
end
end

Workspace.CurrentCamera.FieldOfView = 60

mouse.KeyDown:connect(function(key)
if key == "w" or string.byte(key) == 17 then
if tick()-last < 0.375 then
run()
end
last = tick()
else
last = 0
end
end)

mouse.KeyUp:connect(function(key)
if key == "w" or string.byte(key) == 17 then
if running then
walk()
end
end
end)

Let's see what I can do with it...

~Kill The Clones is the best game on ROBLOX!~
Report Abuse
Henderick is not online. Henderick
Joined: 10 Dec 2007
Total Posts: 1523
01 May 2013 07:02 PM
Strangely enough, key == "w" actually works.

I don't think what you wrote works; I already a connection line for the keys down function but I didn't mention it earlier, so the problem didn't lie there.

I already tried using key:byte(), but that didn't work either ><.
Report Abuse
Henderick is not online. Henderick
Joined: 10 Dec 2007
Total Posts: 1523
01 May 2013 07:04 PM
Also, I'm trying to get my sprinting function to work directly with "w" + "shift" being pressed at the same time, only. I don't really like the idea of double tapping "w"; sometimes it's not practical.
Report Abuse
KilITheClones is not online. KilITheClones
Joined: 19 Mar 2013
Total Posts: 665
01 May 2013 07:05 PM
------------------------------------------This enables sprinting when you press shift and disabled when you let go:

local last = 0

local running = false

local speedboost = 2.2 --speed multiplier

local mouse = game.Players.LocalPlayer:GetMouse()

function run()
running = true
coroutine.resume(coroutine.create(function() --camera fun :D
for i = 1, 3 do
wait()
Workspace.CurrentCamera.FieldOfView = 60+(i*(20/3))
end
end))
if game.Players.LocalPlayer.Character ~= nil then
if game.Players.LocalPlayer.Character:FindFirstChild("Humanoid") ~= nil then
if game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed > (16*(speednote.Value+1))*speedboost-0.1 then
return
end
game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed * speedboost
end
end
end

function walk()
running = false
coroutine.resume(coroutine.create(function()
for i = 1, 3 do
wait()
Workspace.CurrentCamera.FieldOfView = 80-(i*(20/3))
end
end))
if game.Players.LocalPlayer.Character ~= nil then
if game.Players.LocalPlayer.Character:FindFirstChild("Humanoid") ~= nil then
game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed / speedboost
end
end
end

Workspace.CurrentCamera.FieldOfView = 60

mouse.KeyDown:connect(function(key)
if string.byte(key) == 48 then
run()
end
end)

mouse.KeyUp:connect(function(key)
if string.byte(key) == 48 then
if running then
walk()
end
end
end)

----------------OR---------------- if you want it to just be toggleable with shift:

local last = 0

local running = false

local speedboost = 2.2 --speed multiplier

local mouse = game.Players.LocalPlayer:GetMouse()

function run()
running = true
coroutine.resume(coroutine.create(function() --camera fun :D
for i = 1, 3 do
wait()
Workspace.CurrentCamera.FieldOfView = 60+(i*(20/3))
end
end))
if game.Players.LocalPlayer.Character ~= nil then
if game.Players.LocalPlayer.Character:FindFirstChild("Humanoid") ~= nil then
if game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed > (16*(speednote.Value+1))*speedboost-0.1 then
return
end
game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed * speedboost
end
end
end

function walk()
running = false
coroutine.resume(coroutine.create(function()
for i = 1, 3 do
wait()
Workspace.CurrentCamera.FieldOfView = 80-(i*(20/3))
end
end))
if game.Players.LocalPlayer.Character ~= nil then
if game.Players.LocalPlayer.Character:FindFirstChild("Humanoid") ~= nil then
game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed / speedboost
end
end
end

Workspace.CurrentCamera.FieldOfView = 60

mouse.KeyDown:connect(function(key)
if string.byte(key) == 48 then
running = not running
if running then
run()
else
walk()
end
end
end)


~Kill The Clones is the best game on ROBLOX!~
Report Abuse
chaoticregandpledge is not online. chaoticregandpledge
Joined: 04 Dec 2009
Total Posts: 2894
01 May 2013 07:05 PM
...checking to see if w and shift is pressed at the same time is impractical. If they're walking already and use shift, you can check the IsRunning property of their humanoid instead of checking if the w key is down.
--
http://www.roblox.com/Innocent-place?id=23319537 ~ Innocence
Report Abuse
KilITheClones is not online. KilITheClones
Joined: 19 Mar 2013
Total Posts: 665
01 May 2013 07:07 PM
It's the behavior of Sprinting in Minecraft and I think it's a very good implementation of sprinting. You don't even need to move your fingers to another key or keep them resting on another key in case of fast activation

~Kill The Clones is the best game on ROBLOX!~
Report Abuse
chaoticregandpledge is not online. chaoticregandpledge
Joined: 04 Dec 2009
Total Posts: 2894
01 May 2013 07:09 PM
I personally dislike double tapping w to sprint because it stops your movement for a moment. With w + shift you can just move your other finger over.
--
http://www.roblox.com/Innocent-place?id=23319537 ~ Innocence
Report Abuse
Henderick is not online. Henderick
Joined: 10 Dec 2007
Total Posts: 1523
01 May 2013 07:12 PM
It's just that I've been getting feedback on my game that double tapping "w" is not preferred; people apparently like using "shift" more. Personally, I've always liked using "w" + "shift" to sprint as well, since all the FPS games I've played used that key combination.

I've played Minecraft since indev; there's a reason why sprinting is activated by double tapping "w". To begin with, sneaking is used by pressing "shift" and any other key direction, so sprinting would not be ideal with that key. Also, like you said, you don't need to move your finger to another key. However, in a fast paced FPS game, if you don't double tap W precisely to sprint, it will fail, and sometimes lead to your demise. "W" and "shift" is more practical in that sense.

I thank you guys for your feedback!
Report Abuse
Henderick is not online. Henderick
Joined: 10 Dec 2007
Total Posts: 1523
01 May 2013 07:17 PM
Also, I'm trying to make sprinting specifically activate with "w" AND "shift". It's not ideal for a game to start a sprinting animation by just pressing "shift" while standing still at the same time.
Report Abuse
ScrewDeath is not online. ScrewDeath
Joined: 03 Jun 2012
Total Posts: 2700
01 May 2013 07:18 PM
This kind of works :x

wait()
mouse = game.Players.LocalPlayer:GetMouse()
player = game.Players.LocalPlayer
function KeysDown(key)
if key:byte() == 119 then--w
print("w")
mouse.KeyDown:connect(function(x)--define mouse though
if x:byte() == 48 then--shift
print("shift")
if player.Character then
player.Character.Humanoid.WalkSpeed = 50
print("Running")
end
end
end)
end
end
mouse.KeyDown:connect(KeysDown)

mouse.KeyUp:connect(function(ker)
if ker:byte() == 119 or ker:byte() == 48 then
if player.Character then
if player.Character.Humanoid.WalkSpeed == 50 then
player.Character.Humanoid.WalkSpeed = 16
print("Walking")
end
end
end
end)
Report Abuse
Henderick is not online. Henderick
Joined: 10 Dec 2007
Total Posts: 1523
01 May 2013 07:35 PM
aaaa this is not working!! D:
Report Abuse
Henderick is not online. Henderick
Joined: 10 Dec 2007
Total Posts: 1523
01 May 2013 07:38 PM
bump x3 ):
Report Abuse
Henderick is not online. Henderick
Joined: 10 Dec 2007
Total Posts: 1523
01 May 2013 08:00 PM
help please!
Report Abuse
Henderick is not online. Henderick
Joined: 10 Dec 2007
Total Posts: 1523
01 May 2013 08:12 PM
ww
Report Abuse
Henderick is not online. Henderick
Joined: 10 Dec 2007
Total Posts: 1523
01 May 2013 08:17 PM
last bump i suppose
Report Abuse
Henderick is not online. Henderick
Joined: 10 Dec 2007
Total Posts: 1523
01 May 2013 08:42 PM
i guess not
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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