How to make better click to sit chairs?

I’m trying to make click to sit chairs, while not needed and I could do animations (which I’m thinking of doing) I’d like to do click to sit chairs instead, it’s just more pleasing then walking on top of a chair and putting an animation in.

I’ve already made a successful attempt to get the player to the chair, but most of the time the player spawns above or below it, glitching out of the chair and or; gets stuck under the chair. I do not have the code because it’s been deleted, but I understand how to get the player to the chair and such as that. I really just need help making sure the player sits and doesn’t get stuck. But, since I don’t have the code, the way the code worked is it teleported the player to the chair whilst enabling the seat.

4 Likes

Instead of teleporting the character to the seat, why not use Seat:Sit(Humanoid)?
It seems like it would be more reliable than teleporting the character.
You could use a ClickDetector, and get the Character’s Humanoid from the Player object ClickDetector.MouseClick returns.

Could you explain more of it? I’m not very experienced in Seat:Sit. I used a ClickDetector to sense the seat was clicked, and they were teleported on it enabling the seat. I’m a newb at most of scripting.

How are you currently teleporting the player?

You should be using CFrame rather than Position/Vector3, as Vector3 will teleport you above the chair.

Otherwise you can use Seat:Sit. Here’s an article about it here:
https://developer.roblox.com/en-us/api-reference/function/Seat/Sit

If you’d like a code example of Seat:Sit I can do that for you.

If my memory does my well, I was just using the CFrame of the seat, not going above it. I might’ve changed it to Vector3 so It does teleport above it. A code example of it would help, but only if you want to. After reading the article, I grasped how it works, but it’d take some fiddling.

This will work for you most likely.

local Seat = script.Parent.Seat
local ClickDetector = Seat.ClickDetector

ClickDetector.MouseClick:connect(function(plr) -- upon clicking
    if Seat.Occupant then return end -- make sure seat isn't already taken

    local char = plr.Character
    if not char then return end -- make sure the player has a character

    local humanoid = char:FindFirstChildOfClass("Humanoid")
    if not humanoid then return end -- make sure the char has a humanoid
    
    Seat:Sit(humanoid) -- forces the humanoid to sit on the seat
end)

Seat:Sit() is a function used to force a humanoid into a seat. Just refer to the humanoid inside the function parameters and it will make the character sit.

Hope this helps, if you have any further questions don’t hesitate to ask!

1 Like