https://gyazo.com/6e7e5aa596e74e76a7a7689ae41005d7
What is the problem ??:
so basically when I walk or idle it is ok but when I swing everything changes and it break and it will only work again only when i equip and unequip
(I am using client cast so I putted it to server)
Local client to hand the animations :
local Tool = script.Parent
local Player = Tool.Parent.Parent
print(Player)
Player.CharacterAdded:Wait()
local Character = Player.Character
local Humanoid,Animate = Character:WaitForChild("Humanoid"),Character:WaitForChild("Animate")
local Equipped = false
Tool.Equipped:Connect(function()
for _, playingTracks in pairs(Humanoid:GetPlayingAnimationTracks()) do
playingTracks:Stop()
end
Equipped = true
--Character.Animate.walk.WalkAnim.AnimationId = "rbxassetid://11420832921"
--Character.Animate.toolnone.ToolNoneAnim.AnimationId = "rbxassetid://11420835044"
--Character.Animate.idle.Animation1.AnimationId = "rbxassetid://11420835044"
--Character.Animate.idle.Animation2.AnimationId = "rbxassetid://11420835044"
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://11420832921"
local Walk = Humanoid:LoadAnimation(Animation)
--Walk.Priority = Enum.AnimationPriority.Movement
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://11420835044"
local Idle = Humanoid:LoadAnimation(Animation)
--Idle.Priority = Enum.AnimationPriority.Idle
--local Connection2
--Connection2 = Humanoid.Running:Connect(function(Speed)
-- print(Speed)
-- if Speed > 0 then
-- if not Walk.IsPlaying and Idle.IsPlaying then
-- Idle:Stop()
-- Walk:Play()
-- end
-- else
-- if Walk.IsPlaying and not Idle.IsPlaying then
-- Idle:Play()
-- Walk:Stop()
-- end
-- end
--end)
local Connection2
Connection2 = game:GetService("RunService").Heartbeat:Connect(function()
local Magnitude = Humanoid.MoveDirection.Magnitude
if Humanoid.MoveDirection == Vector3.new(0,0,0) then
if Walk.IsPlaying and not Idle.IsPlaying then
Idle:Play()
Walk:Stop()
end
else
if not Walk.IsPlaying and Idle.IsPlaying then
Walk:Play()
Idle:Stop()
end
end
end)
Idle:Play()
--Humanoid.StateChanged:Connect(function(State)
-- if State == Enum.HumanoidStateType.Landed then
-- --Idle:Play()
-- if Magnitude == 0 then
-- Idle:Play()
-- I
-- end
-- -- Walk:Play()
-- --end
-- end
--end)
script.Parent.IdlePlay.OnClientEvent:Connect(function()
wait(2)
Idle:Play()
end)
Tool.Unequipped:Connect(function()
Equipped = false
for i,v in pairs(Player.Character.Humanoid:GetPlayingAnimationTracks()) do
v:Stop()
end
Connection2:Disconnect()
for i,v in pairs(Player.Character.Humanoid:GetPlayingAnimationTracks()) do
v:Stop()
end
Walk:Stop()
Idle:Stop()
local Magnitude = Humanoid.MoveDirection.Magnitude
if Magnitude == 0 then
local WalkID = Animate.idle.Animation1.AnimationId
local Animation = Instance.new("Animation")
Animation.AnimationId = WalkID
local Idle2 = Humanoid:LoadAnimation(Animation)
Idle2:Play()
else
local WalkID = Animate.walk.WalkAnim.AnimationId
local Animation = Instance.new("Animation")
Animation.AnimationId = WalkID
local Walk2 = Humanoid:LoadAnimation(Animation)
Walk2:Play()
local Connection
Connection = Humanoid.Running:Connect(function(Speed)
if Speed == 0 then
Walk2:Stop()
Connection:Disconnect()
end
end)
end
end)
end)
local Connection2
Connection2 = game:GetService("RunService").Heartbeat:Connect(function()
local Magnitude = Humanoid.MoveDirection.Magnitude
if Humanoid.MoveDirection == Vector3.new(0,0,0) then
if Walk.IsPlaying and not Idle.IsPlaying then
Idle:Play()
Walk:Stop()
end
else
if not Walk.IsPlaying and Idle.IsPlaying then
Walk:Play()
Idle:Stop()
end
end
end)
Idle:Play()
There is other script to hand the swing which is in server:
local DataModule = require(game.ServerScriptService.DataCore.DataManager)
local ClientCast = require(game.ServerStorage.ClientCast)
--[[Objects]]
local Tool = script.Parent
local Player = script.Parent.Parent.Parent
local PlayerDataRemote = game:GetService("ReplicatedStorage").Remote.PlayerData
local SwordName = "CurvedSword"
local PlayerData = DataModule.ReturnData(Player,SwordName)
local Damage = PlayerData.Damage
--[[Remote]]
local AnimationPlayRemote = game.ReplicatedStorage.Remote.AnimationPlaying
--We will now start using our client caster
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local casterParams = RaycastParams.new()
casterParams.FilterDescendantsInstances = {Player.Character or Player.Parent.Character,Tool.Blade}
casterParams.FilterType = Enum.RaycastFilterType.Blacklist
local Caster = ClientCast.new(Tool.Blade,casterParams)
local Debounce = {}
Caster:Stop()
Caster:SetOwner(nil)
Caster.Collided:Connect(function(RaycastResult)
local HitHumanoid = RaycastResult.Instance.Parent:FindFirstChild("Humanoid")
if HitHumanoid == nil then return end
if Debounce[HitHumanoid] then
return
end
Debounce[HitHumanoid] = true
HitHumanoid.Health = HitHumanoid.Health - Damage
coroutine.wrap(function()
wait(0.75) -- 75
Debounce[HitHumanoid] = false
end)()
end)
Tool.Activated:Connect(function()
if (os.clock() - PlayerData.Debounce ) < PlayerData.Cooldown then return end
PlayerData.Debounce = os.clock()
local Sounds = {Tool.Blade["Sword Swing"],Tool.Blade["Sword Swing Metal Heavy"]}
local RandSound = math.random(1,#PlayerData.Animations)
Sounds[RandSound]:Play()
local Rand = math.random(1,#PlayerData.Animations)
AnimationPlayRemote:FireAllClients(PlayerData.Animations[Rand],Player)
local animator = Instance.new("Animator")
animator.Parent = Player.Character.Humanoid
-- Create a new "Animation" instance and assign an animation asset ID
local Animation = Instance.new("Animation")
Animation.AnimationId = PlayerData.Animations[Rand]
local SwordTrack = Humanoid:LoadAnimation(Animation)
SwordTrack:Play(0)
Caster:Start()
coroutine.wrap(function()
PlayerDataRemote:FireClient(Player, DataModule.ReturnData(Player,SwordName) )
Humanoid.WalkSpeed = 11
wait(0.75)
Caster:Stop()
Humanoid.WalkSpeed = 16
end) ()
SwordTrack.Stopped:Wait()
script.Parent.IdlePlay:FireClient(Player)
end)
Tool.Unequipped:Connect(function()
Caster:Stop()
end)
There’s the local script for animations so it shows it to the client good(This only been used in the server script where swing happens)
--Animation manager
--[[Services]]
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
--[[Import]]
--[[Dirs]]
local Remote = ReplicatedStorage.Remote
--[[Variables]]
--[[Objects]]
--a
--[[Remote]]
local AnimationRemote = Remote.AnimationPlaying
--[[Functions]]
--[[Application]]
AnimationRemote.OnClientEvent:Connect(function(AnimationID,Player)
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local animator = Instance.new("Animator")
animator.Parent = Player.Character.Humanoid
-- Create a new "Animation" instance and assign an animation asset ID
local Animation = Instance.new("Animation")
Animation.AnimationId = AnimationID
local SwordTrack = Humanoid:LoadAnimation(Animation)
SwordTrack.Priority = Enum.AnimationPriority.Action
SwordTrack:Play(0)
end)
So what I want to get is that when he swings it does not make it animation less for the walk and idle