So I have a script that is at tool, it’s local. The idea is that if the player moves and he is in combat, then play one animation, otherwise the usual animation to reproduce.
local rp = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local startedPlayer = game:GetService("StarterPlayer")
local starterCharacter = startedPlayer:WaitForChild("StarterCharacterScripts")
local RunService = game:GetService("RunService")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local tool = script.Parent
local equipped = false
local event = rp:WaitForChild("Combat")
local Animations = rp:WaitForChild("Animations")
local combatIdle = humanoid:LoadAnimation(Animations:WaitForChild("CombatIdle"))
local idle = humanoid:LoadAnimation(Animations:WaitForChild("Idle"))
local combatWalk = humanoid:LoadAnimation(Animations:WaitForChild("CombatWalk"))
local walk = humanoid:LoadAnimation(Animations:WaitForChild("Walk"))
local data = game.Players.LocalPlayer:WaitForChild("Data")
local inCombat = data.InCombat
inCombat.Value = false
tool.RequiresHandle = false
script.Parent.Equipped:Connect(function()
equipped = true
--print(equipped)
combatIdle:Play()
inCombat.Value = true
idle:Stop()
end)
script.Parent.Unequipped:Connect(function()
equipped = false
--print(equipped)
combatIdle:Stop()
inCombat.Value = false
idle:Play()
end)
game:GetService("RunService").RenderStepped:Connect(function()
print("!") -- PRINT
if humanoid.MoveDirection.Magnitude > 1 and inCombat.Value == true then
walk:Stop()
combatWalk:Play()
print(inCombat.Value) -- DIDN'T PRINT
elseif humanoid.MoveDirection.Magnitude > 1 and inCombat.Value == false then
combatWalk:Stop()
walk:Play()
print(inCombat.Value) -- DIDN'T PRINT
end
end)
The tool equipped is working!
In Output I haven’t errors!
I’ll tell you right away that the bug is that if a player is holding a Combat and he walks, then instead of playing animation, he just goes without animation. And then when he removes combat, the usual animation also stops working)