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

Help with making this keyboard press script change a value?

Asked by 7 years ago

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

Log in to vote
1
Answered by
DanzLua 2879 Moderation Voter Community Moderator
7 years ago
Edited 7 years ago

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

0
What does elseif do? TinyScripter 70 — 7y
0
@TinyScripter its like, if this then that elseif this then that elseif this then that else that end DanzLua 2879 — 7y
0
...? TinyScripter 70 — 7y
Ad

Answer this question