The animation is bugged

I want the animation to play if the player is not idle and the tool is also equipped
so if the player is walking and the tool is also equipped then he animation plays and their speed turns to 32
but if they unequip it
it does the opposite
local script inside tool:

local rem = game:GetService("ReplicatedStorage").RemoteEvent
local rem2 = game:GetService("ReplicatedStorage").rem2
local tool = script.Parent
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local humwalkspeed = hum.WalkSpeed
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://9255499096"

local track = hum:LoadAnimation(animation)
local toolequipped = false

	
	
tool.Equipped:Connect(function()
toolequipped = true
	hum.Running:Connect(function(speed)

			if toolequipped == false and speed <= 0 then return end
		if speed > 0 and toolequipped == true then
	track:Play()
	
			rem:FireServer()
				print("fired")
			
				end
	
		end)
end)

tool.Unequipped:Connect(function()
	toolequipped = false
	hum.Running:Connect(function(speed)	

if speed ==  0 and toolequipped  == false then
	
	track:Stop()
	
			rem2:FireServer(humwalkspeed) 
			end
	end)
end)
3 Likes

What do you mean by it “It does the Opposite”. Is it supposed to keep the speed at 32?

2 Likes

i MEAN it goes back to 16 and the animation stops

1 Like

Maybe the track:Stop() after tool.Unequipped stops the animation? I cant find what makes the speed go back down.

Could you post what the “rem2” RemoteEvent Does?

2 Likes
local rem2 = game:GetService("ReplicatedStorage").rem2
rem2.OnServerEvent:Connect(function(plr,humwalkspeed)
	local char = plr.Character or plr.CharacterAdded:Wait()
	local hum = char:WaitForChild("Humanoid")

	hum.WalkSpeed =  humwalkspeed
	
end)

normal script

2 Likes

I dont see a problem here, what does the other “rem” RemoteEvent do?

2 Likes

heres the full script:
normal script:

local rem2 = game:GetService("ReplicatedStorage").rem2
rem2.OnServerEvent:Connect(function(plr,humwalkspeed)
	local char = plr.Character or plr.CharacterAdded:Wait()
	local hum = char:WaitForChild("Humanoid")

	hum.WalkSpeed =  humwalkspeed
	
end)

normal script 2:

local tool = script.Parent
local rem = game:GetService("ReplicatedStorage").RemoteEvent

rem.OnServerEvent:Connect(function(plr,track)
	local  char = plr.Character or plr.CharacterAdded:Wait()
	local hum = char:WaitForChild("Humanoid")

	
	hum.WalkSpeed =  32

end)

local script(main script):

local rem = game:GetService("ReplicatedStorage").RemoteEvent
local rem2 = game:GetService("ReplicatedStorage").rem2
local tool = script.Parent
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local humwalkspeed = hum.WalkSpeed
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://9255499096"

local track = hum:LoadAnimation(animation)
local toolequipped = false

	
	
tool.Equipped:Connect(function()
toolequipped = true
	hum.Running:Connect(function(speed)

			if toolequipped == false and speed <= 0 then return end
		if speed > 0 and toolequipped == true then
	track:Play()
	
			rem:FireServer()
				print("fired")
			
				end
	
		end)
end)

tool.Unequipped:Connect(function()
	toolequipped = false
	hum.Running:Connect(function(speed)	

if speed ==  0 and toolequipped  == false then
	
	track:Stop()
	
			rem2:FireServer(humwalkspeed) 
			end
	end)
end)

what i want: when u equip the tool your speed will be 32 and an animation is playing if u walk
if u unequip it the animaton stops and return to normal walking animation and your
walkspeed will be the old walkspeed aka 16

1 Like

So from what I understand, the animation is broken, but does the walkspeed change?

2 Likes

this was my old local script before i add in the animation

local rem = game:GetService("ReplicatedStorage").RemoteEvent
local rem2 = game:GetService("ReplicatedStorage").rem2
local tool = script.Parent
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local humwalkspeed = hum.WalkSpeed

hum.Died:Connect(function()
	local clone = tool:Clone()
	clone.Parent = game:GetService("ReplicatedStorage")
	task.wait(0.002)

	tool:Destroy()
	plr.CharacterAdded:Connect(function()
		clone.Parent = game:GetService("StarterPack")
		print("hi")
	end)
end)

tool.Equipped:Connect(function()

	rem:FireServer()
end)

tool.Unequipped:Connect(function()

	rem2:FireServer(humwalkspeed)	
end)

this works but the current local script walkspeed does change but its soo buggy so if i hold d and then activate the tool it wont load the animation or walkspeed but if i stop holding d the animation plays and if i unequp the tool while the animation is playing and plus im idle my walkspeed will be 32
i know its hard to understand