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

I have a KeyCode script with debounce but it dosen't work?


local assetID = 02236125916
local MaxDistance = 25
debounce = false

function onKeyPress(inputOject, gameProcessedEvent)
	if inputObject.Keycode == Enum.KeyCode.R then
		game:GetService("InsertService"):LoadAsset(02236125916).Parent = game.Workspace.Model
		if debounce == false then
				debounce = true
		if game:GetService("UserInputService").InputEnded then
			if debounce == false then
				debounce = true
				game.Workspace["BB GUI"].BillboardGUI.Enabled = false
				wait(1)
				debounce = false
			end
		end
	end
end
	game:GetService("UserInputService").InputBegan:connect(onKeyPress)

I think I might have put the debounce codes in the wrong place, please help!

5 comments

0

Are you gonna use the 'else' statement or no? If no, or waits?

0

@cherrythetree Could you post an example. Also if you could add in a part where you can only use the R key from a certain distance that would be nice!

0

InsertService is server-side only. I recommend using a RemoteEvent.!

0

Btw, if there is assetId then why are you not using it to line 07? And you forgot local in debounce. And I think I will agree incapaz but InsertService can give assets thought.

0

If my answer satisfies your question, please accept it.

1 answer

local assetID, MaxDistance, debounce = 02236125916, 25, false

function onKeyPress(inputObject, gameProcessedEvent) --You spelled 'inputObject' incorrectly. I fixed it.
	if inputObject.Keycode == Enum.KeyCode.R and debounce == false then 
		debounce = true
		game:GetService("InsertService"):LoadAsset(02236125916).Parent = game.Workspace.Model
		while true do
			wait()
			if game:GetService("UserInputService").InputEnded then
				game.Workspace["BB GUI"].BillboardGUI.Enabled = false
				wait(1)
				break
			end
		end
	end
	debounce = false
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)

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