Input Not Detected?

Help with Inputs, Please :slight_smile:

So I coded this Movement Script, But something is wrong, Since when I press the keys, Nothing Happens. Can someone Help me with this?
I’m pretty new to the UserInputService.

Here’s The Script:

--//Settings
local SprintSpeed = 12
local NormalSpeed = 10
local CrouchSpeed = 8

local SprintFOV = 90
local NormalFOV = 80

--//Variables

local Sprint = false
local Crouch = false
local FreeMouse = false

--//Other Variables

local TweenService = game:GetService("TweenService")
local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Char = Player.Character
local Humanoid = Player.Character:WaitForChild("Humanoid")

local Cam = game.Workspace.CurrentCamera
local FOV = game.Workspace.CurrentCamera.FieldOfView

local CamFOVChangeSprint = TweenInfo.new(
	0.5,
	Enum.EasingStyle.Sine,  
	Enum.EasingDirection.InOut,  
	0,                
	false,         
	0  
)

local CamPosChange = TweenInfo.new(
	0.8,
	Enum.EasingStyle.Sine,  
	Enum.EasingDirection.InOut,  
	0,                
	false,         
	0  
)

local CrouchedGoal = {CameraOffset = Vector3.new(0,-2,0)}
local UncrouchedGoal = {CameraOffset = Vector3.new(0,0,0)}

local CrouchedTween = TweenService:Create(Humanoid, CamPosChange, CrouchedGoal)
local UncrouchedTween = TweenService:Create(Humanoid, CamPosChange, UncrouchedGoal)

local ChangeSprintFOV = TweenService:Create(Cam, CamFOVChangeSprint, {FieldOfView = SprintFOV})
local ChangeSprintFOVBack = TweenService:Create(Cam, CamFOVChangeSprint, {FieldOfView = NormalFOV})

local LoadCrouch = Humanoid:LoadAnimation(script.CrouchAnimation)
LoadCrouch.Priority = Enum.AnimationPriority.Action


--//Functions

UIS.InputBegan:Connect(function(Input) -- Tanzende_Bannanen
	--IF FREEMOUSE
	--//
	if Input == Enum.KeyCode.NumLock then
		if FreeMouse == true then
			game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter
			FreeMouse = false
		else
			game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.Default
			FreeMouse = true
		end
	end
	--//
	--IF CROUCH
	--//
	if Input == Enum.KeyCode.LeftControl or Input == Enum.KeyCode.RightControl then
		if Crouch == false then
			LoadCrouch:Play()
			CrouchedTween:Play()
			Crouch = true
			Humanoid.WalkSpeed = CrouchSpeed
			Char:WaitForChild("HumanoidRootPart").CanCollide = false
		else
			LoadCrouch:Stop()
			UncrouchedTween:Play()
			Crouch = false
			Humanoid.WalkSpeed = NormalSpeed
			Char:WaitForChild("HumanoidRootPart").CanCollide = true
		end
	end
	--//
	--IF SPRINT
	--//
	if Input == Enum.KeyCode.LeftShift or Input == Enum.KeyCode.RightShift then
		if Sprint == false then
			Sprint = true
			Humanoid.WalkSpeed = SprintSpeed
			ChangeSprintFOV:Play()
		else
			Sprint = false
			Humanoid.WalkSpeed = NormalSpeed
			ChangeSprintFOVBack:Play()
		end
	end
	--//
end)

--//Setup Camera

Cam.FieldOfView = NormalFOV
Player.CameraMode = Enum.CameraMode.LockFirstPerson --Lock Cam
local mouse = Player:GetMouse() --Change Cursor
mouse.Icon = "http://www.roblox.com/asset/?id=569021388" --Change Cursor

Try doing Input.KeyCode instead of just Input.

2 Likes

Thanks :slight_smile:
That was the Solution, Pretty simple actually.

1 Like

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