Why Doesn't this script work?

Here is my coding;

mouse.KeyDown:connect(function(key)
	if key == "e" and Kick == true then
		local RL = script.Parent:FindFirstChildOfClass("RightFoot")
		RL.Touched:connect(function(hit)
			if Kick == false then return end
			if hit.Name == "Ball" then 
			Kick = false
			local F = Instance.new("BodyVelocity")
			F.Parent = hit
			F.velocity = RL.CFrame.lookVector * 20
			F.maxForce = (script.Parent.Parent.Angle.Value)
		local playAnim2 = humanoid:LoadAnimation(anim2)
		Kick = false
		playAnim2:Play()
		Kick = false
		humanoid.WalkSpeed = 0
		wait(1)
		humanoid.WalkSpeed = 25
				Kick = true
				end
			end)
	end

end)

I dont think it got the RightFoot.
anyway, Thanks for reading!

Can you try using this?

local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E and Kick == true then
		local RL = script.Parent:FindFirstChildOfClass("RightFoot")
		RL.Touched:connect(function(hit)
			if Kick == false then return end
			if hit.Name == "Ball" then 
			Kick = false
			local F = Instance.new("BodyVelocity")
			F.Parent = hit
			F.velocity = RL.CFrame.lookVector * 20
			F.maxForce = (script.Parent.Parent.Angle.Value)
		local playAnim2 = humanoid:LoadAnimation(anim2)
		Kick = false
		playAnim2:Play()
		Kick = false
		humanoid.WalkSpeed = 0
		wait(1)
		humanoid.WalkSpeed = 25
				Kick = true
				end
			end)
	end

end)

No that wont work I dont think, My anim plays normally without the Touched function.

Oh, so is the touched function the problem? Does it output any errors?

Yes; Workspace.devfoum_helper.Anims:43: attempt to index nil with 'Touched'

Alright? is the script inside the player character? if yes, can you try doing this?

local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E and Kick == true then
		local RL = script.Parent:WaitForChild("RightFoot")
		RL.Touched:connect(function(hit)
			if Kick == false then return end
			if hit.Name == "Ball" then 
			Kick = false
			local F = Instance.new("BodyVelocity")
			F.Parent = hit
			F.velocity = RL.CFrame.lookVector * 20
			F.maxForce = (script.Parent.Parent.Angle.Value)
		local playAnim2 = humanoid:LoadAnimation(anim2)
		Kick = false
		playAnim2:Play()
		Kick = false
		humanoid.WalkSpeed = 0
		wait(1)
		humanoid.WalkSpeed = 25
				Kick = true
				end
			end)
	end

end)

tell me if it outputs any error

RightFoot isn’t a class.

Change your code to this:

mouse.KeyDown:connect(function(key)
	if key == "e" and Kick then
		local RL = script.Parent.RightFoot
		
		RL.Touched:connect(function(hit)
			if not Kick then 
				return 
			end
			
			if hit.Name == "Ball" then 
				Kick = false
				
				local F = Instance.new("BodyVelocity")
				F.Velocity = RL.CFrame.LookVector * 20
				F.MaxForce = (script.Parent.Parent.Angle.Value)
				F.Parent = hit
				
				humanoid.WalkSpeed = 0

				local playAnim2 = humanoid:LoadAnimation(anim2)
				playAnim2:Play()
								
				task.wait(1)
				humanoid.WalkSpeed = 25
				
				Kick = true
			end
		end)
	end
end)

Both of your scripts dont seem to work…
nothing in the output!

local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E and Kick == true then
		local RL = script.Parent:WaitForChild("RightFoot")
		RL.Touched:connect(function(hit)
            print("touched")
			if Kick == false then return end
			if hit.Name == "Ball" then 
			Kick = false
			local F = Instance.new("BodyVelocity")
			F.Parent = hit
			F.velocity = RL.CFrame.lookVector * 20
			F.maxForce = (script.Parent.Parent.Angle.Value)
		local playAnim2 = humanoid:LoadAnimation(anim2)
		Kick = false
		playAnim2:Play()
		Kick = false
		humanoid.WalkSpeed = 0
		wait(1)
		humanoid.WalkSpeed = 25
				Kick = true
				end
			end)
	end

end)

Can you test this and tell me if it prints “touched”?

Can you tell me more what does not works with that script?

Yes it prints touched, only like 687 times.
Anim still doesnt play and my ball didnt fling

I used to have the regular anim for when you press ‘‘e’’, That worked, now I want a touched function with it so I made one, and it broke.

I think you’re talking about :basketball: kick animation. Try use :GetTouchingParts on the right foot. This will return a table of the parts that touched the right foot. check is there’s a :basketball: part in it then play the animation.

the script inside the character?

Well as he did on the script i guess yes, i worked with something like that for some of my games, try to put

Local RL = player.Character:WaitForChild("Right Leg")

for sure you should add WaitForChild(“Right Leg”, 0.5)

Ok yes the script is in the startercharacter, I will get back to yall.