InputBegan not working

tryna make a crouch input began thingy and it wont work

local UserInputService = game:GetService("UserInputService")

local plr = game:GetService("Players").LocalPlayer
local character = plr.CharacterAdded:Wait()
local humanoid = character.Humanoid

local speed = 10

local id = "rbxassetid://13377282143"
local animation = humanoid:LoadAnimation(id)

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.C then
		print("hi")
		character = true

		character.Humanoid.WalkSpeed = speed
		animation:Play()
	end
end)

UserInputService.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.C then
		print("hii")
		character = false

		character.Humanoid.WalkSpeed = 16
		animation:Stop()
	end
end)```
1 Like

Is this the full code because you never defined UserInputService

I did, its glitched. idk why but yea

can you send the output? test test test

no error, i checked a million times

you cant set plr.Character to true

remove character = true and character = false and it should work

you also have to create an animation instance. you cant load animations from an id. next time send the output

oh shoot wait, i made two variables the same. whoops, but character is just supposed to be a boolean value i added in a starter character. Ill go fix it and see if anything changes

now im just realizing i didnt even add the character boolean thingy variable


local plr = game:GetService("Players").LocalPlayer
local character = plr.CharacterAdded:Wait()
local humanoid = character.Humanoid

local crouch = character.Variables.Crouched

local speed = 10

local crouchAnimation = Instance.new("Animation")
crouchAnimation.AnimationId = "rbxassetid://13377282143"

local animation = humanoid:LoadAnimation(crouchAnimation)

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.C then
		print("hi")
		crouch = true

		character.Humanoid.WalkSpeed = speed
		animation:Play()
	end
end)

UserInputService.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.C then
		print("hii")
		crouch = false

		character.Humanoid.WalkSpeed = 16
		animation:Stop()
	end
end)```

its literally just stuff from other things, not from the crouch script

local UserInputService = game:GetService("UserInputService")

local plr = game:GetService("Players").LocalPlayer
local character = plr.CharacterAdded:Wait()
local charbool
local humanoid = character.Humanoid

local speed = 10

local id = "rbxassetid://13377282143"

local animationInstance = Instance.new("Animation")
animationInstance.AnimationId = id

local animation = humanoid:LoadAnimation(animationInstance)

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.C then
		print("hi")
		charbool = true

		character.Humanoid.WalkSpeed = speed
		animation:Play()
	end
end)

UserInputService.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.C then
		print("hii")
		charbool = false

		character.Humanoid.WalkSpeed = 16
		animation:Stop()
	end
end)

try that

Is this server Script or LocalScript?
If it’s a LocalScript, I would check to make sure it is parented to a place in which the script can execute, such as StarterCharacterScripts, StarterPlayerScripts, etc.

doesn’t work, idk whats wrong there are 0 errors

its a local script and its in starter character scripts

it works on my end. where is your script located

starter character scripts, its a local script

try changing it to starter player scripts and see what happens

still nothing, i tried starter pack and starter gui too

send output when you press c please