Recently I have been trying to do this.I want the player to sit on a chair by clicking on it.
I added a ClickDetector and inserted a script to make the player sit but it won’t work.
Can you help me?
Can you please post the script you made so we can help you with it. Simply stating “it won’t work” is very unhelpful
function onClick(plr)
plr.Character.Humanoid.Sit = true
As the reply above said please post your script nextime
function Sit(plr)
script.Parent.Parent:Sit(plr.Character.Humanoid)
end
script.Parent.MouseClick:Connect(Sit)
I would first create a server sided script and put it inside the ClickDetector, once done you can copy and paste this code, I think the seat also has a property called Sit so you can easily fit the player in. You shouldn’t need to teleport the player to the seat as that would not work properly.
Thanks this helped a lot!
There is a simple way to make the player also teleport to your chair. This may not be really professional but I think it will do you well.
Things to create in the Explorer
The red marked parts are the chair parts to make them Anchored and CanCollide = true
The yellow marked part should be made Anchored = true CanCollide = false
I have also made PartToSit semi-transparent inorder to see the things we are doing when finished setting up set it to full transparent.
For changing our players orientation we must first make sure we set the PartToSit correct as seen in the capture above I have added a hinge on the Front Surface of the PartToSit.
Script
local clickDetector = script.Parent
clickDetector.MouseClick:Connect(function(player)
local partToSit = clickDetector.Parent:WaitForChild("PartToSit")
player.Character.Humanoid.Sit = true
player.Character.PrimaryPart.CFrame = partToSit.CFrame
end)
In this case our players PrimaryPart is the Head so we set the PartToSit at the level of the head it wont hurt to go over the heads position when sitting down.
Final Product
I think my legs are going through the wood because of the model I currently have.
NOTE: This is my first post and English isn’t my first language so please pardon my mistakes.
This is good but i am using a seat so I don’t think I need this.Still thanks for trying to help me .
This would just make the player sit where they currently are
Try this
local seat = script.Parent
local click = seat.ClickDetector
click.MouseClick:Connect(function(plr)
local hum = workspace[plr.Name]:WaitForChild("Humanoid")
seat.Occupant = hum
end)
I haven’t tried this, I don’t know if it works, please let me know
sorry for being late, but it doesnt work “Unable to assign property Occupant. Property is read only”