Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Convert Deprecated Keyboard Input Into UserInputService?

Asked by 7 years ago
Edited 7 years ago

Simple and easy, but I would like a good thorough way of converting this script into UserInputService. I gave an attempt, but I don't think it worked at all, lol.

Original Script:

local Tool=script.Parent
local V=script.Parent.HandValue.Value
local keys={false,false}
local debris = game:service("Debris")

--[[
(- Example -)
function Key(key)
    if (key=="o") then
        Tool.Movement.Disabled = true
        Tool.GripPos = Vector3.new(0, 0, 0)
        wait(0.05)
        Tool.Movement.Disabled = false
    end
end
]]


function Key1(key)
 if key then
  key = string.lower(key)
  if (key=="e") then
   keys[1]=true
   repeat 
    if script.Parent.PowerValue.Value <= 90 then
    script.Parent.PowerValue.Value=script.Parent.PowerValue.Value+5
    else
    script.Parent.PowerValue.Value=script.Parent.MaxValue.Value
    end
    wait(0.1)
   until keys[1]==false
  end
  if (key=="q") then
   keys[2]=true
   repeat 
    if script.Parent.PowerValue.Value >= 10 then
    script.Parent.PowerValue.Value=script.Parent.PowerValue.Value-5
    else
    script.Parent.PowerValue.Value=script.Parent.MinValue.Value
    end
    wait(0.1)
   until keys[2]==false
  end
 end
end

function Key2(key)
 if key then
  key = string.lower(key)
  if (key=="e") then
   keys[1]=false
  end
  if (key=="q") then
   keys[2]=false
  end
 end
end

function selected(mouse)
 mouse.KeyDown:connect(Key1)
 mouse.KeyUp:connect(Key2)
end

script.Parent.Equipped:connect(selected)

Attempted Converted Script:


local function onInputBegan(input,gameProcessed) if input.UserInputType == Enum.UserInputType.Keyboard then if input.KeyCode == Enum.KeyCode.E then if script.Parent.PowerValue.Value <= 90 then script.Parent.PowerValue.Value=script.Parent.PowerValue.Value+5 else script.Parent.PowerValue.Value=script.Parent.MaxValue.Value end wait(0.1) elseif input.KeyCode == Enum.KeyCode.Q then repeat if script.Parent.PowerValue.Value >= 10 then script.Parent.PowerValue.Value=script.Parent.PowerValue.Value-5 else script.Parent.PowerValue.Value=script.Parent.MinValue.Value end wait(0.1) end end end end

Thanks,

LukeGabrieI aka EnergyBrickz

0
Did you thank yourself? connor12260311 383 — 7y
0
no i meant thanks for reading lol LukeGabrieI 73 — 7y
0
btw, you never even call the function `OnInputBegan`, you should do game:GetService("UserInputService").InputBegan:connect(OnInputBegan) after the function connor12260311 383 — 7y
0
will the second script function the same way without the repeats and the untils in the original script LukeGabrieI 73 — 7y
0
From looking at the repeat in your second code, it seems you're trying to prevent the value from hitting zero; you don't need to go through all that trouble, as you can use the math.max function, which sets a number & the minimum that the value lowers to. :) http://wiki.roblox.com/index.php?title=Global_namespace/Mathematical_functions#math.max (Although, the WIKI shows it differently, and it's sh TheeDeathCaster 2368 — 7y

Answer this question