Herobrinekid2

SERVER SCRIPT

Oct 10th, 2021 (edited)
924
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.54 KB | None | 0 0
  1. local PETS_LIST = require(game.ReplicatedStorage.PETS_LIST)
  2.  
  3.  
  4. local function CREATE_MOVERS(PET)
  5.     local POS = Instance.new("BodyPosition")
  6.     local GYR = Instance.new("BodyGyro")
  7.     POS.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
  8.     POS.P = 1000
  9.     POS.D = 200
  10.    
  11.     GYR.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
  12.     GYR.P = 1000
  13.     GYR.D = 100
  14.    
  15.     POS.Parent = PET
  16.     GYR.Parent = PET
  17. end
  18.  
  19. local function CREATE_NEW(CHAR, NAME, PLAYER)
  20.     if game.ServerStorage.PETS:FindFirstChild(NAME) then
  21.         local NEW = game.ServerStorage.PETS:FindFirstChild(NAME):Clone()
  22.         NEW.CFrame = CHAR.Head.CFrame + Vector3.new(1, 0, 2)
  23.         NEW.Parent = CHAR
  24.         NEW:SetNetworkOwner(PLAYER)
  25.         CREATE_MOVERS(NEW)
  26.        
  27.        
  28.         return NEW
  29.     end
  30. end
  31.  
  32.  
  33. game.Players.PlayerAdded:Connect(function(PLAYER)
  34.     local EQUIPPED_PET = Instance.new("StringValue")
  35.     EQUIPPED_PET.Name = "EQUIPPED_PET"
  36.     EQUIPPED_PET.Parent = PLAYER
  37.    
  38.    
  39.     EQUIPPED_PET.Changed:Connect(function(NAME)
  40.        
  41.         if NAME ~= "" then
  42.             for _, v in pairs(PLAYER.Character:GetChildren()) do
  43.                 if v:IsA("BasePart") then -- // PUT MODEL IF YOUR PET IS A MODEL. MINE IS A BASEPART
  44.                     if table.find(PETS_LIST, v.Name) then
  45.                         v:Destroy()
  46.                     end
  47.                 end
  48.             end
  49.  
  50.  
  51.             local NEW_PET = CREATE_NEW(PLAYER.Character, NAME, PLAYER)
  52.         else
  53.             for _, v in pairs(PLAYER.Character:GetChildren()) do
  54.                 if v:IsA("BasePart") then -- // PUT MODEL IF YOUR PET IS A MODEL. MINE IS A BASEPART
  55.                     if table.find(PETS_LIST, v.Name) then
  56.                         v:Destroy()
  57.                     end
  58.                 end
  59.             end
  60.         end
  61.        
  62.        
  63.     end)
  64. end)
Add Comment
Please, Sign In to add comment