Removing tools while sitting

I have been trying to make a system where if a player sits in a CarSeat or just any seat the tools in there inventory will dissapear but when they get off the seat they reappear if thta makes sence, i just need help on how to do that

1 Like

You could do this by detecting when the state of the player changes (e.g: from standing to sitting), and then disabling the inventory CoreGUI. Lastly, removing any tools the player currently has equipped.

Some rough pseudocode you can play around with. Assumed to be a LocalScript running somewhere on the client.

local char = script.Parent --//This script can go in StarterCharacterScripts container

local function ToggleInventory(sittingDown)
game.StarterGui:SetCoreGuiEnabled("Backpack", not sittingDown) --//Toggle the backpack UI

if sittingDown then --//Remove any tool the user is currently holding, if they are seated
local equippedTool = char:FindFirstChildOfClass("Tool")

if equippedTool then

equippedTool:Destroy()
end
end
end

char:WaitForChild("Humanoid").HumanoidStateChanged:Connect(function(_, newState)
ToggleInventory(newState == Enum.HumanoidStateType.Seated)
end)

It’s been awhile, so I do not exactly remember if disabling the backpack UI also disables the equipping/unequipping of tools. Either way, this should be pretty close for your use case.

1 Like

Hi! For this, I think you can check the state of the player, then if you are using the default Roblox toolbox, you can turn off the CoreGui, then when a player state is not sitting, enable the CoreGui.

An example to achieve this:

local Player = game:GetService("Players").LocalPlayer

local character = Player.Character
local humanoid = character:WaitForChild("Humanoid")

humanoid:GetPropertyChangedSignal("Sit"):Connect(function()
	if humanoid.Sit == true then
		game:GetService("StarterGui"):SetCoreGuiEnabled (Enum.CoreGuiType.Backpack, false)
	else
		game:GetService("StarterGui"):SetCoreGuiEnabled (Enum.CoreGuiType.Backpack, true)
	end
end)

It is exactly as @C_Sharper mentioned, I did not want to discard the draft!

*Note: if you want the player to keep their inventory, then don’t unequip the tools, you can hide the gui, their tools should still be there.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.