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

Help with making this keyboard press script change a value?

I am trying to make this script change a value when "Q" has been pressed down. Here is the script:

function onKeyPress(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.Q then
		local Place = true
		if Place then
		game.Players.LocalPlayer.PlaceMode.Value = false
		Place = false
		if not Place then
		game.Players.LocalPlayer.PlaceMode.Value = true
	end
		end
	end
end
 
game:GetService("UserInputService").InputBegan:connect(onKeyPress)

1 answer

✓ Accepted answer

The reason this isn't working properly is because you are setting the value of place down to true every time the function runs

local Place = true
function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.Q then
        if Place==true then Place = false
      	  game.Players.LocalPlayer.PlaceMode.Value = false 
        elseif Place==false then place = true
       	 game.Players.LocalPlayer.PlaceMode.Value = true
        end
     end
end

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

Also your not using elseif

3 comments

0

What does elseif do?

0

@TinyScripter its like, if this then that elseif this then that elseif this then that else that end

0

...?

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