Hello, recently I’ve made a game and I want to make a really weird game where you hang in a chair. I already made the animations, chair and all of the other stuff. But I can’t figure out how to make it so when you join the game, you spawn in the chair and can’t get out. Here’s a quick video of what I have so far.
Hm, this is an interesting idea for a game, well, you could when players spawn, (By the way this is hypothetical, I don’t know if this is true) turn on their sit boolean value in their humanoid and lock them to the chair, the reason for this are seats can be weird, especially in this case. Other than that you just have to have them spawn on the chair seat wait for the character to sit, then dangle the chair over the edge.
Sit is not a function of humanoid, it is a boolean that describes whether or not the player is sitting.
You may be thinking of SeatPart:Sit which takes a Humanoid as it’s only argument.
@DiamondGenius7513 I believe you are thinking of the Humanoid:Sit() function.
The way I personally would do this is using the aforementioned SeatPart:Sit method followed by setting the humanoid’s JumpPower to 0 (prevent them from escaping the seat).
Here’s an example code:
local Players = game:GetService("Players")
local seat = -- Define your Seat Instance.
Players.PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
seat:Sit(character.Humanoid)
character.Humanoid.JumpPower = 0
end)
Ah sorry about that, it looks like it was checking for the player’s character before it loaded in, thus it returned nil when trying to reference it. I switched it to .CharacterAdded instead of .PlayerAdded - let me know if the issue persists.
-- Services
local Players = game:GetService("Players")
-- Variables
local chairFolder = game.Workspace.ChairFolder
-- Table to hold the chair variables, and if they're taken or not
local seatStatus = {
{chair = chairFolder.Chair1, taken = false},
{chair = chairFolder.Chair2, taken = false},
{chair = chairFolder.Chair3, taken = false},
{chair = chairFolder.Chair4, taken = false}
}
function seatPlayers(character)
local hum = character.Humanoid
hum:SetStateEnabled(Enum.HumanoidStateType.Jumping, false) -- To make the player unable to jump
if hum then
-- Looks through all seats in table and checks if they're taken
for i, v in pairs(seatStatus) do
if v.taken == false then -- If it's not taken, it will sit player in it, and stop looping through the table
v.chair:Sit(hum)
v.taken = true
break
else -- If it is taken, it will continue until the end of the table, or until it finds a chair not taken
end
end
end
end
Players.CharacterAdded:Connect(seatPlayers) -- Fires the seatPlayers function when a player joins the game
Add a spawn location somewhere, and add the following script.
local Spawn = game.Workspace.SpawnLocation
local Seat = game.Workspace.Seat
Spawn.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("HumanoidRootPart") then
local HumanoidRootPart = hit.Parent.HumanoidRootPart
for i = 0,1,0.1 do
wait()
HumanoidRootPart.CFrame = HumanoidRootPart.CFrame:Lerp(Seat.CFrame, i)
end
end
end)
-- Services
local Players = game:GetService("Players")
-- Variables
local chairFolder = game.Workspace.ChairFolder
-- Table to hold the chair variables, and if they're taken or not
local seatStatus = {
{chair = chairFolder.Chair1, taken = false},
{chair = chairFolder.Chair2, taken = false},
{chair = chairFolder.Chair3, taken = false},
{chair = chairFolder.Chair4, taken = false}
}
function seatPlayers(player)
local character = player.Character or player.CharacterAdded:Wait()
local hum = character.Humanoid
hum:SetStateEnabled(Enum.HumanoidStateType.Jumping, false) -- To make the player unable to jump
if hum then
-- Looks through all seats in table and checks if they're taken
for i, v in pairs(seatStatus) do
if v.taken == false then -- If it's not taken, it will sit player in it, and stop looping through the table
v.chair:Sit(hum)
v.taken = true
break
else -- If it is taken, it will continue until the end of the table, or until it finds a chair not taken
end
end
end
end
Players.PlayerAdded:Connect(seatPlayers) -- Fires the seatPlayers function when a player joins the game