Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --// Variables
- local RunService = game:GetService("RunService").Stepped --| Since Scripts can't access RenderStepped or Heartbeat we can simply put Stepped.
- local Event = game.ReplicatedStorage.Equip
- local PetFolder = game.Workspace:WaitForChild("PetsFolder")
- --// Functions
- game.Players.PlayerRemoving:Connect(function(plr)
- --| We don't want users to have pets just hanging around after the user has left right?
- --| This checks if the user has a pet still instanced in the Folder and deletes it.
- if PetFolder:FindFirstChild(plr.Name) then
- PetFolder[plr.Name]:Destroy()
- end
- end)
- Event.OnServerEvent:Connect(function(plr, _Pet)
- --| _Pet is the pet we want to clone. Sent from the client, Take note try and not to trust the client.
- --| This event isn't practical however you can add a "Legitify" if statement to check if the user does infact own the pet sent from the client.
- --| I.E leaderstats. Check if the _Pet exists and then check if the user owns it.
- if not PetFolder:FindFirstChild(plr.Name) then --| If the user has a pet already equipped.
- local hmr = plr.Character:WaitForChild("HumanoidRootPart")
- local Pet = _Pet:Clone()
- Pet.Parent = PetFolder
- Pet.Name = plr.Name
- local P, G --| P = Body Position, G = BodyGyro.
- if Pet:IsA("BasePart") then --| Makes this compatible with Models or just parts!
- P = Pet.BodyPosition
- G = Pet.BodyGyro
- elseif Pet:IsA("Model") then
- P = Pet.PrimaryPart.BodyPosition
- G = Pet.PrimaryPart.BodyGyro
- end
- RunService:Connect(function()
- P.Position = hmr.Position + 3 * hmr.CFrame.RightVector + 1.5 * hmr.CFrame.UpVector - 3 * hmr.CFrame.lookVector
- G.CFrame = hmr.CFrame
- end)
- else
- PetFolder[plr.Name]:Destroy()
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement