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:

01function onKeyPress(inputObject, gameProcessedEvent)
02    if inputObject.KeyCode == Enum.KeyCode.Q then
03        local Place = true
04        if Place then
05        game.Players.LocalPlayer.PlaceMode.Value = false
06        Place = false
07        if not Place then
08        game.Players.LocalPlayer.PlaceMode.Value = true
09    end
10        end
11    end
12end
13 
14game: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

01local Place = true
02function onKeyPress(inputObject, gameProcessedEvent)
03    if inputObject.KeyCode == Enum.KeyCode.Q then
04        if Place==true then Place = false
05          game.Players.LocalPlayer.PlaceMode.Value = false
06        elseif Place==false then place = true
07         game.Players.LocalPlayer.PlaceMode.Value = true
08        end
09     end
10end
11 
12game: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