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

How do you make a stand up button using the same key as a sit down script?

Asked by 4 years ago
Edited 4 years ago

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 '='

0
You forgot to add an end to the "if" statement in line 12 TheNINJA152 85 — 4y
0
And you also wrote "if Character.Humanoid.Sit = true then" it's supposed to be == TheNINJA152 85 — 4y
0
the script works, but my character still doesn't stand up. Thanks for the help, though ILikeBaked_Beans 12 — 4y

1 answer

Log in to vote
0
Answered by
Mayk728 855 Moderation Voter
4 years ago
Edited 4 years ago
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)
Ad

Answer this question