Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

KeysUp, or something like that?

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.

3 comments

0

use uis.InputEnded.

0

so then would I use KeysDown still?

0

I'm sorry, I wasn't reading your code. The lack of indents make it hard to read.

1 answer

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.