So i made a tool loader
meaning one script that loads all my tool animations, im not sure if the code is the best so i need your help to tell me any problems with it!
local Weapon_System = function(W_S)
if not W_S then
---//SERVICES
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
---//PLAYERS
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local RightArm = Character:WaitForChild("Right Arm")
---//LIBARIES
local Libaries = ReplicatedStorage:WaitForChild("Libraries")
local Client_Cast = require(Libaries:WaitForChild("ClientCast"))
---//FUNCTIONS
local Tool_Animations = function(Tool)
if Tool then
local Cast = Client_Cast.new(Tool.Handle, RaycastParams.new())
local ActionAnimations = Tool.Weapon_System.Animations.ActionAnimation:GetChildren()
local EquipAnimation = Humanoid.Animator:LoadAnimation(Tool.Weapon_System.Animations.IdleAnimations.EquipAnimation)
local IdleAnimation = Humanoid.Animator:LoadAnimation(Tool.Weapon_System.Animations.IdleAnimations.IdleAnimation)
EquipAnimation:Play()
EquipAnimation.Stopped:Wait()
IdleAnimation:Play()
Tool.Activated:Connect(function()
if Tool.Weapon_System.Configuration.WaitBoolen.Value == false then
Tool.Weapon_System.Configuration.WaitBoolen.Value = true
Humanoid.Animator:LoadAnimation(ActionAnimations[math.random(1, #ActionAnimations)]):Play()
wait(Tool.Weapon_System.Configuration.Cooldown.Value)
Tool.Weapon_System.Configuration.WaitBoolen.Value = false
end
end)
else
for _, v in pairs(Humanoid:GetPlayingAnimationTracks()) do
if v.Name:match("IdleAnimation") then
v:Stop()
end
end
end
end
--//CONTECT
Character.ChildAdded:Connect(function(Tool)
if Tool:IsA("Tool") then
Tool_Animations(Tool)
end
end)
Character.ChildRemoved:Connect(function()
Tool_Animations()
end)
end
end
return Weapon_System