After I die weird?

I have a localo scirpt in an image button and normally it works but after I die and click on it slows me and I don’t crouch and I can’t go back to my orig speed

local animationId = "17667816899"

--// Variables
local UserInputService = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer

-- Reference the CrouchButton
local TextButton = script.Parent -- Directly reference the parent of the script

local crouching = false
local animationTrack

-- Function to Setup Character
local function setupCharacter(character)
	local humanoid = character:WaitForChild("Humanoid")
	local animator = humanoid:FindFirstChildOfClass("Animator")

	if not animator then
		warn("Animator not found in humanoid! Creating a new one.")
		animator = Instance.new("Animator")
		animator.Parent = humanoid
	end

	-- Animation Setup
	local animation = Instance.new("Animation")
	animation.AnimationId = "rbxassetid://" .. animationId

	animationTrack = animator:LoadAnimation(animation)
	animationTrack.Priority = Enum.AnimationPriority.Action

	-- Reset Crouch State
	crouching = false

	-- Function to Update Animation Speed
	local function updateAnimationSpeed()
		if humanoid.MoveDirection.Magnitude > 0 then
			animationTrack:AdjustSpeed(1) -- Play at normal speed when moving
		else
			animationTrack:AdjustSpeed(0) -- Pause animation when idle
		end
	end

	-- Function to Toggle Crouch
	local function toggleCrouch()
		if crouching then
			humanoid.WalkSpeed = 16
			crouching = false
			animationTrack:Stop()
			character.HumanoidRootPart.CanCollide = true
		else
			humanoid.WalkSpeed = 8
			crouching = true
			if not animationTrack.IsPlaying then
				animationTrack:Play()  -- Play the animation only if it's not already playing
			end
			character.HumanoidRootPart.CanCollide = false
		end

		-- Update animation speed when crouch state changes
		updateAnimationSpeed()
	end

	-- Connect Text Button (check if button is clicked)
	TextButton.Activated:Connect(function()
		print("Button Clicked!")  -- Debug print to ensure button click works
		toggleCrouch()  -- Trigger crouch logic
	end)

	-- Monitor Movement to Update Animation Speed Dynamically
	humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
		if crouching then
			updateAnimationSpeed()
		end
	end)
end

-- Setup for Current Character
if player.Character then
	setupCharacter(player.Character)
end

-- Listen for Character Respawning
player.CharacterAdded:Connect(function(newCharacter)
	setupCharacter(newCharacter)
end)

Very hard to understand your question, mostly because of the terrible use of grammar. Also, I’m not sure this script is yours, because in the scripts you have comments that have perfect English grammar. While in the topic’s title and description… you do not.

ye sorry well um when I die and click on the image button on my script which is a crouch button it doesn’t do the function it should for example I should crouch and get slower and when I click again I should return to normal and get faster speed like normal but it only slows me with no animation or crouching and when I click again I’m still slow

Does this happen always you reset or rarely?

Why don’t you just use a keyboard input instead of a text button.

I already have but this one is for mobile users

always happens like always when I die or respawn

Your english is making this overly hard to understand. Also, why are you using .Activated? That does not work at all. Use .MouseButton1Up and see if that works.

Instead of a text button why don’t you just use ContextActionService? It makes the mobile buttons for you and you can just bind them to the same function.