#TweenService causing Pet to spin horizontally when it should only be slightly moving up and down
1 messages · Page 1 of 1 (latest)
Script:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local Player = Players.LocalPlayer
local PetsConfig = require(ReplicatedStorage.Configs.Pets)
local StateManager = require(ReplicatedStorage.Client.State)
local Remotes = ReplicatedStorage.Remotes.Pets
local GuiTemplate = ReplicatedStorage.PetGui
local EquippedPets: { [string]: { [string]: PetsConfig.PetInstance } } = {}
local PetPositions = {
{
Position = Vector3.new(0, 1, 10),
Orientation = Vector3.new(0, -90, 0)
},
{
Position = Vector3.new(-7.5, 1, 8),
Orientation = Vector3.new(0, -120, 0)
},
{
Position = Vector3.new(7.5, 1, 8),
Orientation = Vector3.new(0, -60, 0)
},
}
local function GetPetOrder(character: Model)
local petFolder = character:FindFirstChild("Pets")
if not petFolder then return 1 end
if #petFolder:GetChildren() == 0 then
return 1
end
local activeSlots = {}
for _, pet in petFolder:GetChildren() do
local order = pet.Order.Value
activeSlots[order] = order
end
for availableSlot = 1, 5, 1 do
if not activeSlots[availableSlot] then
return availableSlot
end
end
end
local function PetFollow(player: Player, pet: PetsConfig.PetInstance)
local character = player.Character or player.CharacterAdded:Wait()
if not character then return end
local humanoidRootPart: Part = character:WaitForChild("HumanoidRootPart")
if not humanoidRootPart then return end
local pets = EquippedPets[tostring(player.UserId)]
if not pets then return end
pets[pet.UUID] = pet
local petsFolder = character:FindFirstChild("Pets")
if not petsFolder then
petsFolder = Instance.new("Folder", character)
petsFolder.Name = "Pets"
end
local petModel: Model = ReplicatedStorage.Pets:FindFirstChild(pet.Model):Clone()
petModel:PivotTo(humanoidRootPart.CFrame)
local charAttachment = Instance.new("Attachment", humanoidRootPart)
charAttachment.Visible = false
local petAttachment = Instance.new("Attachment", petModel.PrimaryPart)
petAttachment.Visible = false
local alignPosition = Instance.new("AlignPosition", petModel)
alignPosition.MaxForce = 25_000
alignPosition.Responsiveness = 25
alignPosition.Attachment0 = petAttachment
alignPosition.Attachment1 = charAttachment
local alignOrientation = Instance.new("AlignOrientation", petModel)
alignOrientation.MaxTorque = 25_000
alignOrientation.Responsiveness = 25
alignOrientation.Attachment0 = petAttachment
alignOrientation.Attachment1 = charAttachment
local order = Instance.new("IntValue", petModel)
order.Name = "Order"
order.Value = GetPetOrder(character)
local petPosition = PetPositions[order.Value]
charAttachment.Position = petPosition.Position
charAttachment.Orientation = petPosition.Orientation
petModel.Name = pet.UUID
petModel.Parent = petsFolder
local tweenInfo = TweenInfo.new(1)
local upTween = TweenService:Create(charAttachment, tweenInfo, {
Position = Vector3.new(charAttachment.Position.X, 1.5, charAttachment.Position.Z),
Orientation = Vector3.new(charAttachment.Orientation.X, charAttachment.Orientation.Y, -5)
})
local downTween = TweenService:Create(charAttachment, tweenInfo, {
Position = Vector3.new(charAttachment.Position.X, 0, charAttachment.Position.Z),
Orientation = Vector3.new(charAttachment.Orientation.X, charAttachment.Orientation.Y, 5)
})
upTween.Completed:Connect(function()
downTween:Play()
end)
downTween.Completed:Connect(function()
upTween:Play()
end)
upTween:Play()
local gui = GuiTemplate:Clone()
gui.Parent = petModel.PrimaryPart
gui.Frame.PetName.Text = pet.Name
gui.Frame.Rarity.Text = pet.Rarity
end
local function PetStopFollow(player: Player, uuid: string)
local pets = EquippedPets[tostring(player.UserId)]
if not pets then return end
pets[uuid] = nil
local character = player.Character
if not character then return end
local petsFolder = character:FindFirstChild("Pets")
if not petsFolder then return end
local model = petsFolder:FindFirstChild(uuid)
if model then
model:Destroy()
end
end
local function InitalizePlayer(player: Player)
local pets = EquippedPets[tostring(player.UserId)]
if not pets then return end
for uuid, pet in pets do
PetFollow(player, pet)
end
end
Remotes.EquipPet.OnClientEvent:Connect(function(uuid)
local petInstance = StateManager.GetData().Pets[uuid]
local pets = EquippedPets[tostring(Player.UserId)]
pets[uuid] = petInstance
PetFollow(Player, petInstance)
end)
Remotes.UnequipPet.OnClientEvent:Connect(function(uuid)
PetStopFollow(Player, uuid)
end)
Remotes.RenamePet.OnClientEvent:Connect(function(uuid: string, name: string)
local pets = EquippedPets[tostring(Player.UserId)]
local character = Player.Character
if not character then return end
local petFolder = character:FindFirstChild("Pets")
if not petFolder then return end
local petModel: Model = petFolder:FindFirstChild(uuid)
if not petModel then return end
local gui = petModel.PrimaryPart:FindFirstChildOfClass("BillboardGui")
if gui then
gui.Frame.PetName.Text = name
end
end)
Remotes.ReplicateEquipPet.OnClientEvent:Connect(PetFollow)
Remotes.ReplicateUnequipPet.OnClientEvent:Connect(PetStopFollow)
StateManager.GetData()
EquippedPets = Remotes.GetEquippedPets:InvokeServer()
for _, player in Players:GetPlayers() do
player.CharacterAdded:Connect(function(character)
InitalizePlayer(player)
end)
InitalizePlayer(player)
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
InitalizePlayer(player)
end)
InitalizePlayer(player)
end)
Did you animate it wrong?
** You are now Level 1! **
Also it kinda looks like in the script it's not an animation so you can replace the position move with a load animation
And then make the animations just the pets floating up and down
It's not an animation.
I do not know how to and I don't want it animated. The tween is only supposed to move it up and down 10 studs slowly so that it looks like it's hovering
the tween works perfectly fine. but for some reason, the one in slot 1 turns slightly and it shouldn't
Yea? That just looks nice. Also whatch out for preston, he might DMCA you
Saying this cuz im too lazy to read script
Animations im fine at
But scripts? Nuhuh
I don't know how to animate tho
It's easy to say it's easy when someone knows how to. But when someone doesn't know how to, it's not easy until they are taught how to.