Hello everyone, I need help by creating an code which plays an animation with items, I already got a script which plays the animation but the items/tools are not in it.
ProximityPrompt.Triggered:Connect(function(plr) -- gets the player
local hum = plr.Character:WaitForChild("Humanoid") -- gets the player's humanoid
local loadAnim = hum.Animator:LoadAnimation(Anim) -- loads animation
loadAnim:Play() -- plays the animation
end)```
I already searched after it and i did not found anything, I would appreciate for a response.
Here is an video with what I mean: https://streamable.com/43lj2w?src=player-page-share
You’ll have to weld the items to the player’s hands via a script. Since there’s an item on each hand, should make 2 welds. The script i made below will weld the items to players when they join
-- put this script in ServerScriptService
local item = game.ReplicatedStorage.item:Clone() -- put your item here
local item2 = game.ReplicatedStorage.item2:Clone() -- put your item here
function CreateWeld(character)
local weld = Instance.new("Weld", character)
local weld2 = Instance.new("Weld", character)
-- put items inside players so they become visible
item.Parent = character
item2.Parent = character
-- attaching weld to the hands
weld.Part0 = character.RightHand
weld.Part1 = item
weld2.Part0 = character.LeftHand
weld2.Part1 = item2
-- You'll probably also have to adjust the weld's C0 and C1 to match the item's correct position too
weld.C0 = CFrame.new(0,1,0) * CFrame.Angles(0,math.rad(90),0)
weld.C1 = CFrame.new(1,0,0) * CFrame.Angles(0,0,math.rad(45))
end
-- attach items to player hands when they join
game.Players.ChildAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
CreateWeld(character)
end)
end)
One last note is if the item is a model that contains multiple parts, you’ll have weld all parts to a “main” part then weld that part to the hands