Advertisement
Marcel12311

Roblox script follow pet[Fixed]

Jan 4th, 2022 (edited)
3,523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.03 KB | None | 0 0
  1. --[[
  2. ------------
  3. INSTRUCTION:
  4. ------------
  5. 1.Create Script and put to ServerScriptService
  6. 2.Copy all code below to script..
  7. 3.Create Model change name to Pet and put to ReplicatedStorage
  8. 4.Create inside Model(Pet) Part and (change name Pet)
  9. 5.Go to Model(Pet)->Part(Pet) and inside of Part create BodyGyro and BodyPosition don't change name
  10. 6.in BodyPosition change (D = 1250) and (MaxForce = 8000,8000,8000) and (P = 6000)
  11. 7.Run!
  12.  
  13. ------------
  14. if you did well what I described above, you will have no problems...
  15. if you have problems/bugs/errors pm me in game!
  16. My Profile:
  17. https://www.roblox.com/users/140427102/profile
  18.  
  19. Tutorial how to script configure:
  20. https://www.youtube.com/watch?v=8FIQGebSk9M
  21. ------------
  22.  
  23. Enjoy guys! this Fixed version of pet following don't edit it if you don't know what you are doing
  24. --]]
  25.  
  26. local part = nil -- handle to our animal
  27. local BodyPosition = nil -- animal position in the world 3D
  28. local BodyGyro = nil -- speed of the animal's turnover
  29.  
  30. local StoreSearched = {} -- store variable bool of players (if we eqiupped pet don't create anymore pets on account) this variable holds false/true of players
  31. local storeCharacters = {} -- store characters of players
  32. local storeHeads = {} -- storage humanoid heads of players
  33. local StoreSearched2 = {} -- it does the same as above
  34.  
  35. local players = game:GetService("Players")
  36. local pets = game.ReplicatedStorage:FindFirstChild("Pet")
  37. local petsinv = nil -- Store Clone pet
  38.  
  39. game.Players.PlayerAdded:Connect(function(plr)
  40.     plr.CharacterAdded:Connect(function()
  41.         StoreSearched2[plr.Name] = false
  42.     end)
  43. end)
  44.  
  45. game.Players.PlayerRemoving:Connect(function(plr)
  46.     StoreSearched[plr.Name] = nil
  47.     storeCharacters[plr.Name] = nil
  48.     storeHeads[plr.Name] = nil
  49.     StoreSearched2[plr.Name] = nil
  50. end)
  51.  
  52. while wait(0.010) do
  53.     for i,v in pairs(players:GetPlayers()) do
  54.         if v then
  55.             if storeCharacters[v.Name] then    
  56.                 if storeCharacters[v.Name] ~= nil and storeCharacters[v.Name]:FindFirstChild("Humanoid") and storeCharacters[v.Name].Humanoid.Health > 0 and StoreSearched2[v.Name] == false then
  57.                     for i,s in pairs(storeCharacters[v.Name]:GetChildren()) do
  58.                         if s:IsA("Model") and s.Name == "Pet" then
  59.                             StoreSearched[v.Name] = true
  60.                             break
  61.                         else
  62.                             StoreSearched[v.Name] = false
  63.                         end
  64.                     end
  65.  
  66.                     if StoreSearched[v.Name] == false then
  67.                         print("this player don't have pet")
  68.  
  69.                         if pets and storeCharacters[v.Name].Humanoid.Health > 0 then
  70.                             local petsinv = pets:Clone()
  71.                             petsinv.Parent = storeCharacters[v.Name]
  72.                             petsinv:PivotTo(storeHeads[v.Name].CFrame)
  73.                         end
  74.                     end
  75.                 end
  76.  
  77.                 if storeCharacters[v.Name].Humanoid.Health <= 0 and storeCharacters[v.Name]:FindFirstChild("Pet") then
  78.                     StoreSearched2[v.Name] = true
  79.                     storeCharacters[v.Name].Pet:Destroy()
  80.                 end
  81.  
  82.             end
  83.         end
  84.     end
  85.  
  86.  
  87.     for i,v in pairs(players:GetPlayers()) do
  88.         if v then
  89.             storeCharacters[v.Name] = v.Character
  90.             if not storeCharacters[v.Name] then
  91.                 storeCharacters[v.Name] = v.CharacterAdded:Wait()
  92.             end
  93.             if storeCharacters[v.Name] then
  94.                 storeHeads[v.Name] = storeCharacters[v.Name]:FindFirstChild("UpperTorso")
  95.                 if storeHeads[v.Name] ~= nil then
  96.                     part = (storeCharacters[v.Name]:FindFirstChild("Pet") and storeCharacters[v.Name].Pet:FindFirstChild("Pet"))
  97.                     if part ~= nil then
  98.                         BodyGyro = part.BodyGyro
  99.                         BodyPosition = part.BodyPosition
  100.                         if v and BodyGyro ~= nil and BodyPosition ~= nil then
  101.                             part.CFrame = CFrame.new(part.Position,storeHeads[v.Name].Position) * CFrame.Angles(0,math.rad(0),0)
  102.                             BodyGyro.CFrame = CFrame.new(part.Position,storeHeads[v.Name].Position) * CFrame.fromEulerAnglesXYZ(0,math.rad(45),0)
  103.                             if storeHeads[v.Name].Size.Magnitude <= 77 then
  104.                                 BodyPosition.Position = storeHeads[v.Name].Position + (storeHeads[v.Name].Size /2) + Vector3.new(3.3,3.3,3.3)
  105.                             else
  106.                                 BodyPosition.Position = storeHeads[v.Name].Position + (storeHeads[v.Name].Size /1.7)
  107.                             end
  108.                         end
  109.  
  110.                     end
  111.                 end
  112.  
  113.             end
  114.  
  115.         end
  116.     end
  117.  
  118.  
  119.  
  120. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement