I recently made a sword animation on a tool and I animated the handle using Motor6d, I originally made a local script for the animation but the sword handle animation doesn’t replicate, I then decide to make it a server script instead but the problem is that I can’t get the character from the server script…
External MediaThis is the script:
local tool = script.Parent
local humanoid
local animationTrack
local UIS = game:GetService("UserInputService")
local toolEnable
local Player = game.Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local SwordStyles = require(game.ReplicatedStorage.Modules:WaitForChild("SwordStyles"))
local styleName = "Yoru"
local db = false
local m6d
tool.Equipped:Connect(function()
local a:Weld = character:FindFirstChild("Right Arm"):WaitForChild("RightGrip")
m6d = Instance.new("Motor6D")
m6d.Parent = character:FindFirstChild("Right Arm")
m6d.Name = "RightGrip"
m6d.Part0 = a.Part0
m6d.Part1 = a.Part1
m6d.C0 = a.C0
m6d.C1 = a.C1
a:Destroy()
local animationInstance = tool:FindFirstChildOfClass("Animation")
if animationInstance then
humanoid = tool.Parent:FindFirstChildOfClass("Humanoid")
if humanoid then
animationTrack = humanoid:LoadAnimation(animationInstance)
animationTrack:Play()
end
-- Add code to play sounds, spawn particle effects, etc.
toolEnable = UIS.InputBegan:Connect(function(input,isTyping)
if not isTyping and db == false then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
SwordStyles:Attack(Player, styleName)
end
end
end)
end
end)
tool.Unequipped:Connect(function()
toolEnable:Disconnect()
m6d:Destroy()
local animationInstance = tool:FindFirstChildOfClass("Animation")
if animationTrack then
animationTrack:Stop()
end
end)