So, I made a script so that when you press the Q key, you sit down. How do you make a script to stand up by pressing the button again?
this is the script:
01 | local plr = game.Players.LocalPlayer |
02 | local uis = game:GetService( "UserInputService" ) |
03 |
04 | uis.InputBegan:Connect( function (key,_) |
05 | if key.KeyCode = = Enum.KeyCode.Q then |
06 | if plr.Character ~ = nil then |
07 | plr.Character.Humanoid.Sit = true |
08 | end |
09 | end |
10 | end ) |
11 |
12 | if plr.Character.Humanoid.Sit = true then --this is the standing up part i tried adding. |
13 | uis.InputBegan:Connect( function (key,_) |
14 | if key.KeyCode = = Enum.KeyCode.Q then |
15 | if plr.Character ~ = nil then |
16 | plr.Character.Humanoid.Sit = false |
17 | end |
18 | end |
19 | end ) |
The only solution i could find is make the stand up part use a different key. also, i get this error when i test the script: Expected 'then' when parsing if statement, got '='
01 | local plr = game:GetService( 'Players' ).LocalPlayer |
02 | repeat wait() until plr.Character and plr.Character:FindFirstChild( 'Humanoid' ) |
03 | local char = plr.Character |
04 | local hum = char.Humanoid |
05 |
06 | local UIS = game:GetService( 'UserInputService' ) |
07 |
08 | local Sitting = false |
09 | UIS.InputBegan:Connect( function (input,proc) --proc will prevent it from activating while ur typing in any TextBoxes, such as chat. |
10 | if input.KeyCode = = Enum.KeyCode.Q and not proc then |
11 | if not Sitting then |
12 | Sitting = true |
13 | hum.Sit = true |
14 | elseif Sitting then |
15 | Sitting = false |
16 | hum.Sit = false |
17 | end |
18 | end |
19 | end ) |
shorter method:
01 | local plr = game:GetService( 'Players' ).LocalPlayer |
02 | repeat wait() until plr.Character and plr.Character:FindFirstChild( 'Humanoid' ) |
03 | local char = plr.Character |
04 | local hum = char.Humanoid |
05 |
06 | local UIS = game:GetService( 'UserInputService' ) |
07 |
08 | UIS.InputBegan:Connect( function (input,proc) --proc will prevent it from activating while ur typing in any TextBoxes, such as chat. |
09 | if input.KeyCode = = Enum.KeyCode.Q and not proc then |
10 | hum.Sit = not hum.Sit |
11 | end |
12 | end ) |