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:
local plr = game.Players.LocalPlayer local uis = game:GetService("UserInputService") uis.InputBegan:Connect(function(key,_) if key.KeyCode == Enum.KeyCode.Q then if plr.Character ~= nil then plr.Character.Humanoid.Sit = true end end end) if plr.Character.Humanoid.Sit = true then --this is the standing up part i tried adding. uis.InputBegan:Connect(function(key,_) if key.KeyCode == Enum.KeyCode.Q then if plr.Character ~= nil then plr.Character.Humanoid.Sit = false end end 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 '='
local plr = game:GetService('Players').LocalPlayer repeat wait() until plr.Character and plr.Character:FindFirstChild('Humanoid') local char = plr.Character local hum = char.Humanoid local UIS = game:GetService('UserInputService') local Sitting = false UIS.InputBegan:Connect(function(input,proc) --proc will prevent it from activating while ur typing in any TextBoxes, such as chat. if input.KeyCode == Enum.KeyCode.Q and not proc then if not Sitting then Sitting = true hum.Sit = true elseif Sitting then Sitting = false hum.Sit = false end end end)
shorter method:
local plr = game:GetService('Players').LocalPlayer repeat wait() until plr.Character and plr.Character:FindFirstChild('Humanoid') local char = plr.Character local hum = char.Humanoid local UIS = game:GetService('UserInputService') UIS.InputBegan:Connect(function(input,proc) --proc will prevent it from activating while ur typing in any TextBoxes, such as chat. if input.KeyCode == Enum.KeyCode.Q and not proc then hum.Sit = not hum.Sit end end)