How could i perfectly align the handle to the viewmodel placed in camera and how can i make myself stop flying
Video:
Code:
-- ToolScript
local Tool = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ViewModelManager = require(ReplicatedStorage.Managers:WaitForChild("ViewModelManager"))
local AnimationManager = require(ReplicatedStorage.Managers:WaitForChild("AnimationManager"))
local equip = workspace.Sons["1.6"]
local function weldParts(part0, part1)
local weld = Instance.new("Weld")
weld.Part0 = part0
weld.Part1 = part1
weld.C0 = part0.CFrame:ToObjectSpace(part1.CFrame)
weld.Parent = part0
print("Weld created between", part0.Name, "and", part1.Name)
end
Tool.Equipped:Connect(function()
ViewModelManager:DestroyViewModel()
equip:Play()
local ViewModel = ViewModelManager:CreateViewModel("VM_cartao")
local animations = AnimationManager:LoadAnimations(ViewModel, { "Cartao" })
animations.Cartao:Play()
ViewModelManager:BindViewModel(ViewModel)
local viewModelPart = ViewModel:FindFirstChild("Cart")
if viewModelPart then
local toolHandle = Tool:FindFirstChild("Handle")
if toolHandle then
toolHandle.CFrame = viewModelPart.CFrame
weldParts(toolHandle, viewModelPart)
else
print("Tool handle not found.")
end
else
print("ViewModel part 'CartaoHandle' not found.")
end
end)
Tool.Unequipped:Connect(function()
ViewModelManager:RecreateDefaultViewModel()
end)