What is wrong with this script?

The question in the title,
I try to make a script where I can fly with a jetpack. Now the keyboard controls work. But the controller controls aren’t working.

UIS.InputBegan:Connect(function(input,ignore)
	if ignore then return end

	if input.KeyCode == keybind or input.KeyCode == xbox_keybind then
		Enable(Enum.UserInputState.Begin)
	end

	if enabled then
		if input.KeyCode == Enum.KeyCode.W then
			forward = 1
		end
		if input.KeyCode == Enum.KeyCode.S then
			backward = -1
		end

		if input.KeyCode == Enum.KeyCode.D then
			right = 1
		end
		if input.KeyCode == Enum.KeyCode.A then
			left = -1
		end
		if input.KeyCode == Enum.KeyCode.Thumbstick1 then
			local x,y = input.Keycode.Position.X,input.Keycode.Position.Y
			print(y,x)
			if y >= 0.1 then
				forward = 1
			end
			if y <= -0.1 then
				backward = -1
			end

			if x >= 0.1 then
				right = 1
			end
			if x <= -0.1 then
				left = -1
			end
		end
	end
end)
1 Like

Some of this script appears to be missing, would you be able to share it?

1 Like

try this maybe?

UIS.InputBegan:Connect(function(input,ignore)
	if ignore then return end

	if input.KeyCode == keybind or input.KeyCode == xbox_keybind then
		Enable(Enum.UserInputState.Begin)
	end

	if enabled then
		if input.KeyCode == Enum.KeyCode.W then
			forward = 1
		elseif input.KeyCode == Enum.KeyCode.S then
			backward = -1
		end

		if input.KeyCode == Enum.KeyCode.D then
			right = 1
		elseif input.KeyCode == Enum.KeyCode.A then
			left = -1
		end
		if input.KeyCode == Enum.KeyCode.Thumbstick1 then
			local x,y = input.Keycode.Position.X,input.Keycode.Position.Y
			print(y,x)
			if y >= 0.1 then
				forward = 1
			end
			if y <= -0.1 then
				backward = -1
			end

			if x >= 0.1 then
				right = 1
			end
			if x <= -0.1 then
				left = -1
			end
		end
	end
end)
1 Like

Try checking for UserInputType for checking controller inputs and use that if statement to check for controller inputs.

1 Like