Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

3 comments

0

You forgot to add an end to the "if" statement in line 12

0

And you also wrote "if Character.Humanoid.Sit = true then" it's supposed to be ==

0

the script works, but my character still doesn't stand up. Thanks for the help, though

1 answer

✓ Accepted answer
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)

This discussion is preserved as it was. New answers, comments, and votes are closed.