I’m trying to pick up a pet with humanoid. After pressing F key, the remote event will be triggered, the pet will tween on the shoulder and I used weldconstraint so that the pet will go with the player. Here is the remoteevent code I used:
-- This code is under ServerScriptService with name "RemoteHandler"
local replicatedStorage = game:GetService("ReplicatedStorage")
local tweenService = game:GetService("TweenService")
local pickupItem = replicatedStorage:WaitForChild("PickupItem")
-- I intentionally make the tween long to see the effect.
local pickupTweenInfo = TweenInfo.new(
5,
Enum.EasingStyle.Linear,
Enum.EasingDirection.In,
0,
false,
0
)
pickupItem.OnServerEvent:Connect(function(player, model)
local char = player.Character
local finishCFrame = char.UpperTorso.CFrame:ToWorldSpace(CFrame.new(0, 2, 0))
model.HumanoidRootPart.Anchored = true
local tween = tweenService:Create(model.HumanoidRootPart, pickupTweenInfo, {CFrame=finishCFrame})
tween:Play()
local weldConstraint = Instance.new("WeldConstraint")
weldConstraint.Name = "TempWeld"
weldConstraint.Part0 = model.HumanoidRootPart
weldConstraint.Part1 = char.UpperTorso
weldConstraint.Parent = model.HumanoidRootPart
end)
However, the tween did do what I want to do. The pick up object stay in the place although weld to player and make the player move with the object.
I felt like this is due to the below code:
local finishCFrame = char.UpperTorso.CFrame:ToWorldSpace(CFrame.new(0, 2, 0))
Somehow, the object was not tween to the top of upper torso…
Is this the right way? I’ve been looking around to find tutorial to pick up another humanoid, but without success. Any suggestions?
Thank you so much!