Guest User

GrabManager(ServerSide)

a guest
Apr 18th, 2025
664
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. local Storage = game:GetService("ReplicatedStorage")
  2. local PhysicsService:PhysicsService = game:GetService("PhysicsService")
  3. local PlayerService = game:GetService("Players")
  4.  
  5. local Checker = require(Storage.Modules.GrabbableChecker)
  6. local PlateHandler = require(Storage.Modules.PlateHandler)
  7.  
  8.  
  9. function Drop(Player:Player)
  10. local Object:BasePart = Checker.GrabbedObjects[Player.UserId]
  11. if Object then
  12. Checker.GrabbedObjects[Player.UserId] = nil
  13. Object.CollisionGroup = "default"
  14. Object:SetNetworkOwnershipAuto()
  15. Storage.Events.Release:FireClient(Player)
  16. end
  17. end
  18. Storage.Events.Release.OnServerEvent:Connect(Drop)
  19.  
  20. PlayerService.PlayerAdded:Connect(function(Player)
  21. PhysicsService:RegisterCollisionGroup(Player.UserId)
  22. PhysicsService:CollisionGroupSetCollidable(Player.UserId,Player.UserId,false)
  23.  
  24. Player.CharacterAdded:Connect(function(Character)
  25. Character:FindFirstChildOfClass("Humanoid").Died:Connect(function()
  26. Drop(Player)
  27. end)
  28. for _,Limb in Character:GetChildren() do
  29. if Limb:IsA("BasePart") then
  30. Limb.CollisionGroup = Player.UserId
  31. end
  32. end
  33. end)
  34. end)
  35. PlayerService.PlayerRemoving:Connect(function(Player)
  36. PhysicsService:UnregisterCollisionGroup(Player.UserId)
  37. Drop(Player)
  38. end)
  39.  
  40. Storage.Events.Grab.OnServerEvent:Connect(function(Player,Object:BasePart)
  41. PlateHandler.DetachFromPlate(Object)
  42. Checker.Check(Object)
  43. if Checker.Grabbable then
  44. --plate weldy thingy
  45. if Object.Name == "Plate" then
  46. PlateHandler.WeldStackOnPlate(Object)
  47. end
  48. --end of plate weldy thingy
  49. Checker.GrabbedObjects[Player.UserId] = Object
  50. Object.CollisionGroup = Player.UserId
  51.  
  52. if Object.AssemblyLinearVelocity then
  53. Object.AssemblyLinearVelocity = Vector3.new(0,0,0)
  54. end
  55. if Object.AssemblyAngularVelocity then
  56. Object.AssemblyAngularVelocity = Vector3.new(0,0,0)
  57. end
  58.  
  59. Object:SetNetworkOwner(Player)
  60.  
  61. end
  62. end)
Advertisement
Add Comment
Please, Sign In to add comment