Even though its set to false its still playing it when moving

basically i have a flashlight, i dont use the backpack because it kinda looks ugly for me of course

so when the “equippedques” is set to true it should play the apropiate animations for equiping and moving it
if its set to false is should play the dequip animation but not play the walking animation when it is set to false

local animationwalk = script:WaitForChild("walk")
local animationidle = script:WaitForChild("idle")
local animationequip = script:WaitForChild("equip")
local animationdeqiup = script:WaitForChild("deqiup")
local flashlight = game.ReplicatedStorage.flashlight
local flashmodel = flashlight:Clone()
local flashprox = flashlight.ProximityPrompt
flashlight.Parent = workspace

local equippedques = false

local destroyflash = workspace:FindFirstChild("flashlight")

local viewhuman = game.Workspace.CurrentCamera:WaitForChild("viewmodel").Humanoid.Animator
local realhuman = script.Parent:WaitForChild("Humanoid")
local RunService = game:GetService("RunService")
local walking = viewhuman:LoadAnimation(animationwalk)
local idle = viewhuman:LoadAnimation(animationidle)
local equipped = viewhuman:LoadAnimation(animationequip)
local dequipped = viewhuman:LoadAnimation(animationdeqiup)
local isequipped = false
print("Walking Animation Loaded:", walking)

flashprox.Triggered:Connect(function()
	flashlight:Destroy()
	
	local userinput = game:GetService("UserInputService")
	userinput.InputBegan:Connect(function(input, gameProcessedEvent)
		if input.KeyCode == Enum.KeyCode.F and equippedques == false then
			equippedques = true
			equipped:Play()
			idle:Play()
			if equippedques == true then
				realhuman.Running:Connect(function(movementSpeed)
					if movementSpeed > 0 then
						if not walking.IsPlaying then
							print("Starting Walking Animation")
							idle:Stop()	
							walking:Play()
						end
					else
						if walking.IsPlaying then
							print("Stopping Walking Animation")
							walking:Stop()
							idle:Play()
						end
					end
				end)
			end
			
			elseif input.KeyCode == Enum.KeyCode.F and equippedques == true then
			dequipped:Play()
			if walking.IsPlaying then
				walking:Stop()
			end
			if idle.IsPlaying then
				idle:Stop()
			end
				equippedques = false
			
		end
	end)
end)

as you can see the walk thing should only play if its set to true

but its still playing even though its shouldnt

please explain why
(if you want you can modiy it to maybe improve it thanks!!)

Every time the flashlight is triggered, you’re adding a new connection to the Running event. To fix this, you should move the realhuman.Running:Connect function outside of the flashprox.Triggered event handler
Try this:

-- Connect to Running event when the flashlight is equipped
realhuman.Running:Connect(function(movementSpeed)
    if movementSpeed > 0 then
        if not walking.IsPlaying then
            print("Starting Walking Animation")
            idle:Stop()
            walking:Play()
        end
    else
        if walking.IsPlaying then
            print("Stopping Walking Animation")
            walking:Stop()
            idle:Play()
        end
    end
end)

flashprox.Triggered:Connect(function()
    flashlight:Destroy()

    local userinput = game:GetService("UserInputService")
    userinput.InputBegan:Connect(function(input, gameProcessedEvent)
        if input.KeyCode == Enum.KeyCode.F and equippedques == false then
            equippedques = true
            equipped:Play()
            idle:Play()
        elseif input.KeyCode == Enum.KeyCode.F and equippedques == true then
            dequipped:Play()
            if walking.IsPlaying then
                walking:Stop()
            end
            if idle.IsPlaying then
                idle:Stop()
            end
            equippedques = false
        end
    end)
end)

Hello coolyoshi,
It seems that you only removed the running event on the thing

I dont really seem to see a difference maybe im wrong because im on my phone right now but ill still try it tommorow even though looks like nothing is changed on the script you provided

If there is an change please tell me because again im in mobile.

just fixed it dont reply thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.