I am trying to make a first person sword fighting game and i tried to animate the sword but when I try to play it in the game it looks alot weaker than in the animation editor.
Animation Editor:
In Game:
Script:
local sword = game.ReplicatedStorage.Sword:Clone()
sword.Parent = workspace
local plr = game.Players.LocalPlayer
local idle = sword.Humanoid.Animator:LoadAnimation(script.Idle)
local swing1 = sword.Humanoid.Animator:LoadAnimation(script.Swing1)
local swing = false
local swingcd = false
repeat wait() until plr.Character:FindFirstChild("HumanoidRootPart")
plr:GetMouse().Button1Down:Connect(function()
if swingcd == false then
swingcd = true
swing = true
wait(0.5)
swingcd = false
end
end)
game:GetService("RunService").RenderStepped:Connect(function()
sword:SetPrimaryPartCFrame(workspace.CurrentCamera.CFrame-Vector3.new(0,1.5,0))
if swing == false then
idle:Play(0,100000000)
else
idle:Stop()
swing1:Play(0,100000000)
swing = false
end
end)
An animation published with Action priority should not need to have it also set from script. Just double check that it’s really published that way.
But, your script has other issues. Why are you passing 100000000 to Play as the animation weight? That’s supposed to be a number between 0 and 1, normally 1 (which is the default if you omit it). Secondly, you’re calling Stop() and Play() 60 times per second on the RenderStepped event. That’s not what you want to do, you want one Stop and one Play call per swing of the sword. When you play the sword swing, don’t wait 0.5 seconds, wait for the track.Ended event (make sure it’s not set to loop).
The Mouse object is also ancient. You should really use ContextActionService or UserInputService for handling all user input events.
Thanks for the tips! I set the animation weight to that number because I was messing around with the script trying to see of changing some values would fix it.
New script with your tips:
local sword = game.ReplicatedStorage.Sword:Clone()
sword.Parent = workspace
local plr = game.Players.LocalPlayer
local idle = sword.Humanoid.Animator:LoadAnimation(script.Idle)
idle.Priority = Enum.AnimationPriority.Idle
local swing1 = sword.Humanoid.Animator:LoadAnimation(script.Swing1)
swing1.Priority = Enum.AnimationPriority.Action
local swing2 = sword.Humanoid.Animator:LoadAnimation(script.Swing2)
swing2.Priority = Enum.AnimationPriority.Action
local swingcd = false
local counter = 1
idle:Play()
repeat wait() until plr.Character:FindFirstChild("HumanoidRootPart")
game:GetService("UserInputService").InputBegan:Connect(function(key)
if key.UserInputType == Enum.UserInputType.MouseButton1 then
if swingcd == false then
swingcd = true
if counter == 1 then
counter = 2
swing1:Play()
else
counter = 1
swing2:Play()
end
wait(0.14)
sword.Sword.Trail.Enabled = true
wait(0.2)
sword.Sword.Trail.Enabled = false
end
end
end)
swing1.Ended:Connect(function()
swingcd = false
end)
swing2.Ended:Connect(function()
swingcd = false
end)
game:GetService("RunService").RenderStepped:Connect(function()
sword:SetPrimaryPartCFrame(workspace.CurrentCamera.CFrame)
end)