Sit to click bricks, are they possible?

Hello! I’m wondering if it’s entirely possible to have a script whereas let’s say you have multiple chair’s in a baseplate, and if you click on one of them it’ll sit you on it, something like welding the character to it unless they jump, i’m curious as to if it is possible without using actual seats as well, and if the chair can have multiple Click brick’s inside it that only weld to one of the bricks with a value inside it, little hard to explain but is anything like that possible? thanks.

Example photo.

Would it be some sort of script in either ServerScriptService or something else? like it detects all the blocks and the value and would weld part of the character to the block? i’m not sure my self, if anyone can help it would be appreciated!

1 Like

I don’t know how to script it, but I guess you can have a click detector and when you click, it make the sitting part a chair part and teleports you on to it?
Hope I gave you a logical idea :slight_smile:

I’m wondering if it’s possible without click detectors, like just a script that can detect if a normal block is clicked, hope that makes sense!

Yes, use a ClickDetector, detect when it’s clicked, get the character from the player that clicked and then use Seat:Sit(Character.Humanoid).

I don’t think there’s an alternative to a click detector…

It’s just that it’s gonna be a bit of a pain putting a click detector in each and every seat, so i’m wondering if there’s an easier way like what i said in the post

Well yeah technically it’s possible. One solution that I can think of is using Mouse.Target. You can detect a mouse click with UserInputType.MouseButton1, then check the Mouse.Target and if it’s a seat then use the same thing I mentioned up Seat:Sit(). You’d have to do this locally tho, or send the Mouse.Target on the server with a RemoteEvent and make the player sit to that seat (wouldn’t make much sense to do it like that tho, better to just do everything on the client).

You could get the Descendants inside the chair using GetDescendants(), & find the Instance ClickDetector, and you can create your event inside there

Yes, you can detect if a mouse is hovering or clicking on a part without a ClickDetector and then make it a remote function or something similar

I’m talking about using no clickdetector, would it be something like Mouse.Target like the other person said?

Just tested and it works with the solution I gave.
https://gyazo.com/b481809be1bbbbe0b15ae559729384e1
Code:

local mouse = game.Players.LocalPlayer:GetMouse();

local maxdistance = 16;
game:GetService("UserInputService").InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		if mouse.Target ~= nil and mouse.Target:IsDescendantOf(workspace.Seats) and (game.Players.LocalPlayer.Character:GetPrimaryPartCFrame().Position - mouse.Target.Position).Magnitude < maxdistance then
			mouse.Target:Sit(game.Players.LocalPlayer.Character.Humanoid)
		end
	end
end)

I just put all the seats in a folder named “Seats” in the workspace and checked if the mouse.Target is descendant of that folder.

Alrighty i will try this code!

1 Like

I think i got a little confused here, which part of explorer does the script with the code go into?

Oh, I just put it in a LocalScript inside of StarterCharacterScripts. You can change the location wherever you prefer tho.

Oh right, the code works great! but is it possible to achieve something like this:
image
Without actually using a seat either, it’s a little tricky to explain but i hope that explained it better

Yup it’s definitely possible but may I ask why you don’t wanna use easier methods like ClickDetector and seats?

Just want to try something a little different for once :smile:
I was randomly thinking one day and this came into my mind, but i’m obviously not the best coder in the world, so i thought i’d ask here instead! hope it doesn’t bother you

Oh alright. Well, you can use WeldConstraints for this. Teleport the player to the “seat” brick:

Character:SetPrimaryPartCFrame(Seat.CFrame)

However, this would make the character go inside of the seat, which we don’t want so:

Character:SetPrimaryPartCFrame(Seat.CFrame * CFrame.new(0, Character.PrimaryPart.Size / 2, 0)

Now, we only need to weld the character to the seat:

local Weld = Instance.new("WeldConstraint")
Weld.Part0 = Character.PrimaryPart
Weld.Part1 = Seat
Weld.Parent = Character.PrimaryPart
Weld.Enabled = true

Why weld constraints? Cause they don’t move the Part0 towards Part1.

No problem, I’m bored anyways so it’s always good to help people instead of doing nothing.

Do you think you would be able to provide a sample of what the full code for this would look like? as i said i’m not the best programmer, and thanks for being really helpful so far! i do appreciate it!

1 Like

It’s actually pretty easy, just combine everything I gave you togheter into a normal LocalScript. Is something confusing you in the script I provided? If so you can tell me so I can explain you.