Advertisement
Navarone19_CH

Bed System

Mar 18th, 2022
935
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. local Cooldown = 1
  2. local CurrentPlayer = nil
  3. local CallbackHandler = nil
  4. local CName = 'Cooldown'
  5.  
  6. function StandupFromBed()
  7. if CurrentPlayer ~= nil and script.Parent:FindFirstChild("WeldConstraint") then
  8. local C = Instance.new("StringValue", CurrentPlayer)
  9. C.Name = CName
  10. game.Debris:AddItem(C, Cooldown)
  11. script.Parent.WeldConstraint:Remove()
  12. if CallbackHandler ~= nil then
  13. CallbackHandler:disconnect()
  14. CallbackHandler = nil
  15. end
  16. CurrentPlayer.Humanoid.PlatformStand = false
  17. CurrentPlayer.HumanoidRootPart.CFrame = script.Parent.CFrame * CFrame.Angles(0, math.rad(180), 0) + Vector3.new(0, 5, 0)
  18. CurrentPlayer.HumanoidRootPart.Anchored = true
  19. wait()
  20. CurrentPlayer.HumanoidRootPart.Anchored = false
  21. CurrentPlayer = nil
  22. end
  23. end
  24.  
  25. function LayToBed(character)
  26. if character ~= nil and not script.Parent:FindFirstChild("WeldConstraint") then
  27. CurrentPlayer = character
  28. CurrentPlayer.HumanoidRootPart.CFrame = script.Parent.CFrame * CFrame.Angles(math.rad(90), 0, math.rad(-90))
  29. CurrentPlayer.Humanoid.PlatformStand = true
  30. local Weld = Instance.new("WeldConstraint", script.Parent)
  31. Weld.Part0 = script.Parent
  32. Weld.Part1 = character.HumanoidRootPart
  33. CallbackHandler = CurrentPlayer.Humanoid.Changed:Connect(function(property)
  34. if CurrentPlayer ~= nil and property == 'Jump' then
  35. StandupFromBed()
  36. end
  37. end)
  38. end
  39. end
  40.  
  41. script.Parent.Touched:Connect(function(hit)
  42. local Character = hit.Parent
  43. if Character:FindFirstChild("Humanoid") and CurrentPlayer == nil and not Character:FindFirstChild(CName) then
  44. LayToBed(Character)
  45. end
  46. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement