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

How to make a script to test if a player is holding a key and clicking?

1 answer

✓ Accepted answer
local plr = game:GetService("Players").LocalPlayer
local mouse = plr:GetMouse()
local UIS = game:GetService("UserInputService")
local key = Enum.KeyCode.E
local IsDown = Instance.new("BoolValue")
IsDown.Parent = plr
IsDown.Name = "IsDown"

UIS.InputBegan:Connect(function(key,gameProc)
	if not gameProc then
		if key.KeyCode == key then
			IsDown.Value = true
		end
	end
end)

UIS.InputEnded:Connect(function(key,gameProc)
	if not gameProc then
		if key.KeyCode == key then
			IsDown.Value = false
		end
	end
end)

IsDown.Changed:Connect(function(property)
	if IsDown.Value == true then
		mouse.Button1Down:Connect(function()
			--do code
		end)
	end
end)

3 comments

0

no no. NEVER DO ends with )'s inside of ends WITHOUT. ITS UGLY AND UNPROFESSIONAL. Instead of an event, do Event:Wait() then the code

0

how is it ugly

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