i wanted to make it so that the idle anim on the tool thats equipped only plays when they standing still or not doing anything (like sprinting) so i made a script that sends a remote event to show that someone is sprinting, and i also made it so that if the player is doing something that it wont play the anim either the bottom code wont work and the remove event script wont work either
--TOOL CODE--
local humanoid, char, player, rootPart, mouse, cam = nil, nil, nil, nil, nil, workspace
local uis = game:GetService("UserInputService")
local anims = {}
local currentAnim = nil
local runevent = game.ReplicatedStorage.ToolEvents.Running:FindFirstChild("Running")
local notrunevent = game.ReplicatedStorage.ToolEvents.Running:FindFirstChild("NotRunning")
local running = false
runevent.OnClientEvent:Connect(function()
print("running")
running = true
end)
notrunevent.OnClientEvent:Connect(function()
print("not running")
running = false
end)
script.Parent.Equipped:Connect(function()
if running == false then
humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
char = script.Parent.Parent
rootPart = humanoid.RootPart
mouse = player:GetMouse()
anims.idle = humanoid:LoadAnimation(script.IdleAnim)
currentAnim = anims.idle
currentAnim:Play()
end
end)
script.Parent.Unequipped:Connect(function()
if currentAnim then
currentAnim:Stop()
currentAnim = nil
end
end)
uis.InputBegan:Connect(function(input, gpe)
if gpe then return end
if input.KeyCode == Enum.KeyCode.W or input.KeyCode == Enum.KeyCode.A or input.KeyCode == Enum.KeyCode.S or input.KeyCode == Enum.KeyCode.D then
currentAnim:Stop()
else
currentAnim:Play()
end
end)
--REMOTE EVENT CODE--
local character = script.Parent
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
print("found it, its with the player", humanoid.Parent.Name)
end
local animation = humanoid:WaitForChild("Animator")
local myAnimation = Instance.new("Animation")
myAnimation.AnimationId = "rbxassetid://136904793129426"
local animTrack = animation:LoadAnimation(myAnimation)
local uis = game:GetService("UserInputService")
local runevent = game.ReplicatedStorage.ToolEvents.Running:FindFirstChild("Running")
local notrunevent = game.ReplicatedStorage.ToolEvents.Running:FindFirstChild("NotRunning")
uis.InputBegan:Connect(function(input, gpe)
if gpe then return end
if input.KeyCode == Enum.KeyCode.LeftControl then
runevent:FireServer()
animTrack:Play()
humanoid.WalkSpeed = 35
end
end)
uis.InputEnded:Connect(function(input, gpe)
if gpe then return end
if input.KeyCode == Enum.KeyCode.LeftControl then
notrunevent:FireServer()
animTrack:Stop()
humanoid.WalkSpeed = 14
end
end)