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: Key-binding in a Localscript.

Previous Thread :: Next Thread 
Geomaster is not online. Geomaster
Joined: 05 Jul 2008
Total Posts: 1480
28 Apr 2013 10:14 PM
I'm fairly certain "shift" isn't the correct value to call when attempting to use that key for a function, which is why my output returned a nil value. Can anyone tell me how to set the value for pressing (left) shift? Also, do I have the right setup to make the player run only while shift is pressed?


player = game.Players.LocalPlayer
char = player.Character
Mouse = player:GetMouse()

running = false
flash = false

guimain = script.PlayerData

meters = {guimain.Sprint, guimain.Battery}
bars = {guimain.Bars.SprintBar, guimain.Bars.FlashBar}


pcall(function()
char.Head.face:Destroy()
char.Humanoid.WalkSpeed = 8
char.Humanoid.MaxHealth = 50
guimain.Parent = player.PlayerGui
wait()
end)

function updateBar(targ, scale)
if targ:IsA("TextLabel") then
targ.Size = UDim2.new(0, scale, 0, 10)
end
end

Mouse.KeyDown:connect(function(key)

if key == "shift" then
running = true
char.Humanoid.WalkSpeed = 13
while running do
if meters[i].Value ~= 0 then
meters[1].Value = meters[1].Value - 1
wait(.2)
else
running = false
char.Humanoid.WalkSpeed = 8
end
end
end

if key == "E" then
if not flash then flash = true
elseif flash then flash = false
end
end

end)

Mouse.KeyUp:connect(function(key)
if key == "shift" and running then
running = false
char.Humanoid.WalkSpeed = 8
while not running do
if meters[i].Value ~= 100 then
meters[i].Value = meters[i].Value + 1
wait(1.8)
end
end
end
end)

for i,v in pairs(meters) do
v.Changed:connect(function()
updateBar(bars[i], (v.Value/100)*240)
end)
end




Report Abuse
tentastic is not online. tentastic
Joined: 21 Dec 2008
Total Posts: 1417
28 Apr 2013 10:19 PM
You need to specify which shift it is, the right shift or left. I can't call correct format of their names but it should be easy to find.
Report Abuse
Geomaster is not online. Geomaster
Joined: 05 Jul 2008
Total Posts: 1480
28 Apr 2013 10:22 PM
Found it -- it's "0" or 48 in byte.

So now onto my second question: is that the right way to make the player run only while shift's pressed?
Report Abuse
tentastic is not online. tentastic
Joined: 21 Dec 2008
Total Posts: 1417
28 Apr 2013 10:25 PM
Looks right. But I'd suggest testing it, and if it doesn't work don't add more to it. Try simplifying it cause usually scripting problems are caused by over complications.
(I learned this the hard way by making a bunch of true/false tests in the wrong places in a giant script I made when I really only needed one in the right place)
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