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:

01local plr = game.Players.LocalPlayer
02local uis = game:GetService("UserInputService")
03 
04uis.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
10end)
11 
12if plr.Character.Humanoid.Sit = true then --this is the standing up part i tried adding.
13uis.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
19end)

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
01local plr = game:GetService('Players').LocalPlayer
02repeat wait() until plr.Character and plr.Character:FindFirstChild('Humanoid')
03local char = plr.Character
04local hum = char.Humanoid
05 
06local UIS = game:GetService('UserInputService')
07 
08local Sitting = false
09UIS.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
19end)

shorter method:

01local plr = game:GetService('Players').LocalPlayer
02repeat wait() until plr.Character and plr.Character:FindFirstChild('Humanoid')
03local char = plr.Character
04local hum = char.Humanoid
05 
06local UIS = game:GetService('UserInputService')
07 
08UIS.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
12end)
Ad

Answer this question