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

KeysUp, or something like that?

Asked by 8 years ago

I wanted to know, is there such a think as a KeysUp? KeysDown is a think but I want this script below to not repeat the loop once the player lets go of the key, however if KeysUp isn't a think what can I do?

script.Parent.ChildAdded:connect(function(w)
if w.className == "Weld" then
if w.Name == "SeatWeld" then
if w.Part1.Parent:findFirstChild("Humanoid" )~= nil then
local pl = game.Players:GetPlayerFromCharacter(w.Part1.Parent)
if pl ~= nil then
local uis = game:GetService("UserInputService")
local keysDown = {T = false;}


uis.InputBegan:connect(function(input, gpe)
    if not gpe then
        local type = input.UserInputType.Name
        if type == "Keyboard" then
            local key = input.KeyCode.Name
            keysDown[1] = true
            if key == "T" then
                script.Parent.Vehilce.Value = false

                repeat wait() until script.Parent.Vehicle.Value == true
                local Bull = script.Parent.Parent.Gun1Bullet:clone()
                local Vel = Instance.new("BodyVelocity")
                Vel.Parent = Bull
                Bull.Velocity = Bull.CFrame.lookVector*500
                Vel.velocity = Bull.Velocity
                Bull.Anchored = false
                Bull.Transparency = 0
                Bull.Damage.Disabled = false
                Bull.Parent = workspace
                Bull.Fire:Play()
            end
        end
    end
end)
end
end
end 
end
end)
script.Parent.ChildRemoved:connect(function(w)
if w.className == "Weld" then
if w.Name == "SeatWeld" then
if w.Part1.Parent:findFirstChild("Humanoid")~=nil then
local pl = game.Players:GetPlayerFromCharacter(w.Part1.Parent)
if pl ~= nil then

    script.Parent.Vehicle.Value = true

end
end 
end
end
end)
                                                    --Below here is where the KeysUp should be. not 
--sure how to do it though
    uis.InputBegan:connect(function(input, gpe)
    if not gpe then
        local type = input.UserInputType.Name
        if type == "Keyboard" then
            local key = input.KeyCode.Name
            keysUp[1] = true
            if key == "T" then
                script.Parent.Vehice.Value = true



I also tested it in studio without this, the script doesn't work, thank you for all the help.

0
use uis.InputEnded. theCJarmy7 1293 — 8y
0
so then would I use KeysDown still? Conmmander 479 — 8y
0
I'm sorry, I wasn't reading your code. The lack of indents make it hard to read. theCJarmy7 1293 — 8y

1 answer

Log in to vote
0
Answered by
Unlimitus 120
8 years ago

Event though depreciated, I prefer KeyUp and KeyDown because they are a lot simpler than using UIS when doing simple things as checking if a keyboard key is up or not.

local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()

function KeyUp (key)
    if key == "g" then
        print("The key 'G' is up after being down")
    end
end

mouse.KeyUp:connect(KeyUp)
Ad

Answer this question