Advertisement
VulpineChick

Functional Client Sided Seat Function (Roblox)

Sep 29th, 2022
1,378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.00 KB | Gaming | 0 0
  1. local SeatOccupant = nil
  2. function CreateSeat()
  3.     local Part = Instance.new("Part")
  4.     Part.Name = "Seat"
  5.     local localSeatWeld = Instance.new("Weld")
  6.     local LocalTouch = nil
  7.     local WhenJumped = nil
  8.     local SatDebounce = os.clock()
  9.     LocalTouch = game:GetService("RunService").RenderStepped:Connect(function()
  10.         local Character = game:GetService('Players').LocalPlayer.Character
  11.         if Character and Character:FindFirstChildWhichIsA('Humanoid') and Character:FindFirstChildWhichIsA('Humanoid'):GetState()~=Enum.HumanoidStateType.Seated and (Character:FindFirstChild("Torso") or Character:FindFirstChild("UpperTorso")) and os.clock()-SatDebounce >= 2 then
  12.             local Torso = Character:FindFirstChild('Torso') or Character:FindFirstChild("UpperTorso")
  13.             localSeatWeld.C0 = CFrame.new(0,Torso.Size.Y,0)
  14.             local Region = workspace:GetPartBoundsInBox(Part.CFrame,Part.Size,OverlapParams.new({
  15.                 ['MaxParts'] = 100
  16.             }))
  17.             local CharacterWillSit = false
  18.             for _,part in pairs(Region)do
  19.                 if part and part:IsDescendantOf(Character) then
  20.                     Character:FindFirstChildWhichIsA('Humanoid').Sit = true
  21.                     SeatOccupant = Part
  22.                     CharacterWillSit = true
  23.                     break
  24.                 end
  25.             end
  26.             if CharacterWillSit then
  27.                 if not WhenJumped then
  28.                     WhenJumped = Character:FindFirstChildWhichIsA('Humanoid'):GetPropertyChangedSignal('Jump'):Connect(function()
  29.                         if Character:FindFirstChildWhichIsA('Humanoid').Jump == true then
  30.                             localSeatWeld.Parent = nil
  31.                             SatDebounce=os.clock()
  32.                             if WhenJumped then
  33.                                 WhenJumped:Disconnect()
  34.                                 WhenJumped = nil
  35.                             end
  36.                         end
  37.                     end)
  38.                 end
  39.                 localSeatWeld.Parent = Part
  40.                 localSeatWeld.Part0 = Part
  41.                 localSeatWeld.Part1 = Torso
  42.             else
  43.                 if WhenJumped then
  44.                     WhenJumped:Disconnect()
  45.                     WhenJumped = nil
  46.                 end
  47.                 localSeatWeld.Parent = nil
  48.             end
  49.         end
  50.     end)
  51.     return Part
  52. end
  53.  
  54. local Seat = CreateSeat()
  55.  
  56. Seat.Anchored = true
  57. Seat.Parent = workspace
  58. Seat.Position = workspace.SpawnLocation.Position + Vector3.new(0,4,0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement