Player keeps playing animation while in water

So for my game you can sail around and stuff right? and so to run you have to double click w cause it just feels more efficient to me, and when your player runs you gotta have a run anim to fit with it right? so for my game when your in the water (its my own water, it has code but that code doesnt matter) while your floating in it your player when sprinting plays the animation so your running in water also sometimes it doesn’t even go fast when sprinting just plays the animation I really want someone to fix the code cause im a bad scripter

first script:

local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local UIS = game:GetService('UserInputService')
local Run = Humanoid:LoadAnimation(script:WaitForChild("Run"))
local S,Word,Running = " ", "W",false

UIS.InputBegan:Connect(function(Input,IsTyping)
	if IsTyping then return end
	if Input.KeyCode == Enum.KeyCode[Word] then
		S = S..Word
	end

	delay(.3, function()
		if S ~= string.rep(Word,2) then S = "" end
	end)

	if S == tostring(Input.KeyCode):gsub("Enum.KeyCode.",Word) then
		Running = true
		Run:Play()
		Humanoid.WalkSpeed = 32
	end

	local ChangeEnd = UIS.InputEnded:Connect(function(Input)
		if Input.KeyCode == Enum.KeyCode[Word] then
			if S ~= Word then Running = false end
		end
	end)

	repeat wait() until Running == false
	ChangeEnd:Disconnect()
	Run:Stop()
	Humanoid.WalkSpeed = 16
end)

second script:

local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local UIS = game:GetService('UserInputService')
local LastTapped,Tapped = false,false
local Run = Humanoid:LoadAnimation(script:WaitForChild("Run"))

UIS.InputBegan:Connect(function(Input, IsTyping)
	if IsTyping then return end
	if Input.KeyCode == Enum.KeyCode.W then
		if Tapped == false then
			Tapped = true
		else
			LastTapped = true
			Tapped = false
			Run:Play()
			Humanoid.WalkSpeed = 32
		end

		delay(.4, function()
			if Tapped then
				Tapped = false
			end
		end)

	end
end)

UIS.InputEnded:Connect(function(Input, IsTyping)
	if IsTyping then return end
	if Input.KeyCode == Enum.KeyCode.W and LastTapped and not Tapped then
		Humanoid.WalkSpeed = 16
		Run:Stop()
	end
end)

please send a fixed version for both

So your script is working fine but the animation is also playing in your own made water, and you don’t want it to be playing in water, correct?

yes also sometimes it doesnt go fast so partly correct

In the first script, you have to make sure that the player is not in water, you can do this by checking the material the player is walking on, in this case you have to make sure that the water is a unique material.

add this: in the UIS.InputBegan function

if Humanoid.FloorMaterial==Enum.Material.Slate then return end --I chose slate as the water material, you can change it to yours

if the water is not artificial, then you can do Enum.Material.Water

I’m not the problem is that its not a material its just the name of it, its a scripted no collide smooth plastic named water

I haven’t look at your code, only the replies, however this is my take:

If you want to check if the touching part is your water, then you could either check the name of the part or add a boolean attribute into water parts and set it to true, and then in the script check if the part has the water attribute.