Hello,
So I have an Upgrade System in my game. The animations of the tools work just fine but then when I upgrade, my character starts sliding with the pose of the idle animation of the tool. How can I fix this issue?
I will give you guys some codes that may be the issue.
Animation Script (Local Script)
-- Variables
local Player = game.Players.LocalPlayer
local Tool = script.Parent
local Equipped = Tool:WaitForChild("Equipped_")
----------------------------------------------------------------
-- Code
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character:WaitForChild("Humanoid")
local IdleAnimationID = 10145559255
local IdleAnimation = Instance.new("Animation")
IdleAnimation.AnimationId = "rbxassetid://"..IdleAnimationID
local IdleAnimationTrack = Humanoid:LoadAnimation(IdleAnimation)
local IdleAnimationSpeed = 0.25
local WalkAnimationID = 9969492200
local WalkAnimation = Instance.new("Animation")
WalkAnimation.AnimationId = "rbxassetid://"..WalkAnimationID
local WalkAnimationTrack = Humanoid:LoadAnimation(WalkAnimation)
local function EquipTool()
Equipped.Value = true
end
local function UnequipTool()
Equipped.Value = false
end
local function PlayIdle()
IdleAnimationTrack.Priority = Enum.AnimationPriority.Movement
IdleAnimationTrack.Looped = true
IdleAnimationTrack:Play()
IdleAnimationTrack:AdjustSpeed(IdleAnimationSpeed)
end
local function StopIdle()
IdleAnimationTrack:Stop()
end
local function StopWalk()
WalkAnimationTrack:Stop()
end
local function PlayWalk()
WalkAnimationTrack.Priority = Enum.AnimationPriority.Movement
WalkAnimationTrack.Looped = true
WalkAnimationTrack:Play()
end
local function StopAllAnimations()
wait(0.1)
IdleAnimationTrack:Stop()
WalkAnimationTrack:Stop()
end
local function WalkHandler()
while wait() do
if Humanoid.MoveDirection.Magnitude > 0 and Equipped.Value == true then
StopIdle()
PlayWalk()
end
if Humanoid.MoveDirection.Magnitude <= 0 and Equipped.Value == true then
StopWalk()
PlayIdle()
end
if Equipped.Value == false then
StopWalk()
StopIdle()
end
if Equipped.Value == true then
end
end
end
WalkHandler()
Tool.Equipped:Connect(function()
EquipTool()
end)
Tool.Unequipped:Connect(function()
UnequipTool()
StopIdle()
StopWalk()
StopAllAnimations()
end)
end)
Upgrade Script (Server Script)
local ss = game:GetService("ServerStorage")
local weapons = ss:WaitForChild("Weapons")
local remote = script.Parent:WaitForChild("UpgradeWeaponRemote")
local sound = script.Parent:WaitForChild("UpgradeSound")
-------------------------------------------------------------------------
remote.OnServerEvent:Connect(function(player, currentTool)
local index = currentTool:FindFirstChild("Index")
local folderName = currentTool:FindFirstChild("FolderName")
local upgradedTool
local character = player.Character
local backpack = player.Backpack
for i, v in pairs(weapons:FindFirstChild(folderName.Value):GetChildren()) do
if v:FindFirstChild("Index").Value == (index.Value + 1) then
upgradedTool = v:Clone()
end
end
sound:Play()
currentTool:Destroy()
upgradedTool.Parent = backpack
end)
Video of the bug
robloxapp-20221006-1811181.wmv (8.2 MB)
Thanks!
Have a great day!