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

How do I replace KeyDown with UserInputService? [solved]

Asked by 6 years ago
Edited 6 years ago

Guys in my script, I used KeyDown which is deprecated, how do I replace it with UserInputService? (I'm Using Local Script) here is the script:

-- This is A local script, works fine but it's deprecated
local plyr = game.Players.LocalPlayer
local char = plyr.Character or plyr.CharacterAdded:Wait()
local torso = char:WaitForChild('HumanoidRootPart')
local mouse = plyr:GetMouse()
mouse.Icon = 'http://www.roblox.com/asset/?id=1278515766'

mouse.KeyDown:connect(function(key) -- Here is the problem
    if key == 'e' then -- When I press E
local target = mouse.Target
    if target and target:FindFirstChild('Configuration') and target.Configuration:FindFirstChild('Interact') and target.Configuration.Interact.Value >= 1 and mouse.Icon == 'http://www.roblox.com/asset/?id=1278513023' then
        if (target.Position - torso.Position).magnitude <= target.Configuration.Interact.Value *1.5 then
            print(target.Name) -- Do the thing if all conditions are valid.
           end
        end
    end
end)

Thanks for help.

0
Found the solution, Thanks! Sebti23Drives 22 — 6y

Answer this question